mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Prevent double ZHA channel initialization (#36554)
* Preven double channel initialization. * Use a setter for setting ZHA device availability.
This commit is contained in:
parent
8ed1b1782e
commit
1bdbe90d2a
@ -263,9 +263,14 @@ class ZHADevice(LogMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return True if sensor is available."""
|
"""Return True if device is available."""
|
||||||
return self._available
|
return self._available
|
||||||
|
|
||||||
|
@available.setter
|
||||||
|
def available(self, new_availability: bool) -> None:
|
||||||
|
"""Set device availability."""
|
||||||
|
self._available = new_availability
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def zigbee_signature(self) -> Dict[str, Any]:
|
def zigbee_signature(self) -> Dict[str, Any]:
|
||||||
"""Get zigbee signature for this device."""
|
"""Get zigbee signature for this device."""
|
||||||
@ -274,10 +279,6 @@ class ZHADevice(LogMixin):
|
|||||||
ATTR_ENDPOINTS: self._channels.zigbee_signature,
|
ATTR_ENDPOINTS: self._channels.zigbee_signature,
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_available(self, available):
|
|
||||||
"""Set availability from restore and prevent signals."""
|
|
||||||
self._available = available
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(
|
def new(
|
||||||
cls,
|
cls,
|
||||||
|
@ -485,16 +485,20 @@ class ZHAGateway:
|
|||||||
self, sender, profile, cluster, src_ep, dst_ep, message
|
self, sender, profile, cluster, src_ep, dst_ep, message
|
||||||
):
|
):
|
||||||
"""Handle tasks when a device becomes available."""
|
"""Handle tasks when a device becomes available."""
|
||||||
self.async_update_device(sender)
|
self.async_update_device(sender, available=True)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_device(self, sender: zigpy_dev.Device, available: bool = True):
|
def async_update_device(
|
||||||
|
self, sender: zigpy_dev.Device, available: bool = True
|
||||||
|
) -> None:
|
||||||
"""Update device that has just become available."""
|
"""Update device that has just become available."""
|
||||||
if sender.ieee in self.devices:
|
if sender.ieee in self.devices:
|
||||||
device = self.devices[sender.ieee]
|
device = self.devices[sender.ieee]
|
||||||
# avoid a race condition during new joins
|
# avoid a race condition during new joins
|
||||||
if device.status is DeviceStatus.INITIALIZED:
|
if device.status is DeviceStatus.INITIALIZED:
|
||||||
device.update_available(available)
|
device.update_available(available)
|
||||||
|
else:
|
||||||
|
device.available = available
|
||||||
|
|
||||||
async def async_update_device_storage(self):
|
async def async_update_device_storage(self):
|
||||||
"""Update the devices in the store."""
|
"""Update the devices in the store."""
|
||||||
|
@ -7,8 +7,7 @@ def apply_application_controller_patch(zha_gateway):
|
|||||||
def handle_message(sender, profile, cluster, src_ep, dst_ep, message):
|
def handle_message(sender, profile, cluster, src_ep, dst_ep, message):
|
||||||
"""Handle message from a device."""
|
"""Handle message from a device."""
|
||||||
if (
|
if (
|
||||||
not sender.initializing
|
sender.ieee in zha_gateway.devices
|
||||||
and sender.ieee in zha_gateway.devices
|
|
||||||
and not zha_gateway.devices[sender.ieee].available
|
and not zha_gateway.devices[sender.ieee].available
|
||||||
):
|
):
|
||||||
zha_gateway.async_device_became_available(
|
zha_gateway.async_device_became_available(
|
||||||
|
@ -211,7 +211,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
|||||||
if not self.zha_device.is_mains_powered:
|
if not self.zha_device.is_mains_powered:
|
||||||
# mains powered devices will get real time state
|
# mains powered devices will get real time state
|
||||||
self.async_restore_last_state(last_state)
|
self.async_restore_last_state(last_state)
|
||||||
self._zha_device.set_available(True)
|
self._zha_device.available = True
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
|
@ -42,7 +42,7 @@ async def device_switch(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_SWITCH_DEVICE,
|
ieee=IEEE_SWITCH_DEVICE,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ async def device_groupable(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE,
|
ieee=IEEE_GROUPABLE_DEVICE,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ async def test_list_groupable_devices(zha_client, device_groupable):
|
|||||||
|
|
||||||
# Make sure there are no groupable devices when the device is unavailable
|
# Make sure there are no groupable devices when the device is unavailable
|
||||||
# Make device unavailable
|
# Make device unavailable
|
||||||
device_groupable.set_available(False)
|
device_groupable.available = False
|
||||||
|
|
||||||
await zha_client.send_json({ID: 11, TYPE: "zha/devices/groupable"})
|
await zha_client.send_json({ID: 11, TYPE: "zha/devices/groupable"})
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ async def coordinator(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ async def device_fan_1(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE,
|
ieee=IEEE_GROUPABLE_DEVICE,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ async def device_fan_2(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE2,
|
ieee=IEEE_GROUPABLE_DEVICE2,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ async def coordinator(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ async def device_light_1(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE,
|
ieee=IEEE_GROUPABLE_DEVICE,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ async def device_light_2(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE2,
|
ieee=IEEE_GROUPABLE_DEVICE2,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ async def coordinator(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ async def device_light_1(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
nwk=0xB79D,
|
nwk=0xB79D,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ async def device_light_2(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
nwk=0xC79E,
|
nwk=0xC79E,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ async def device_light_3(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
nwk=0xB89F,
|
nwk=0xB89F,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ async def coordinator(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
node_descriptor=b"\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ async def device_switch_1(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE,
|
ieee=IEEE_GROUPABLE_DEVICE,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ async def device_switch_2(hass, zigpy_device_mock, zha_device_joined):
|
|||||||
ieee=IEEE_GROUPABLE_DEVICE2,
|
ieee=IEEE_GROUPABLE_DEVICE2,
|
||||||
)
|
)
|
||||||
zha_device = await zha_device_joined(zigpy_device)
|
zha_device = await zha_device_joined(zigpy_device)
|
||||||
zha_device.set_available(True)
|
zha_device.available = True
|
||||||
return zha_device
|
return zha_device
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user