Prevent double ZHA channel initialization (#36554)
* Preven double channel initialization. * Use a setter for setting ZHA device availability.
This commit is contained in:
1 parent
8ed1b1782e
commit
1bdbe90d2a
9 files changed
+30
-26
No files matched your search
@@ -263,9 +263,14 @@ class ZHADevice(LogMixin):
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if sensor is available."""
|
||||
"""Return True if device is available."""
|
||||
return self._available
|
||||
|
||||
@available.setter
|
||||
def available(self, new_availability: bool) -> None:
|
||||
"""Set device availability."""
|
||||
self._available = new_availability
|
||||
|
||||
@property
|
||||
def zigbee_signature(self) -> Dict[str, Any]:
|
||||
"""Get zigbee signature for this device."""
|
||||
@@ -274,10 +279,6 @@ class ZHADevice(LogMixin):
|
||||
ATTR_ENDPOINTS: self._channels.zigbee_signature,
|
||||
}
|
||||
|
||||
def set_available(self, available):
|
||||
"""Set availability from restore and prevent signals."""
|
||||
self._available = available
|
||||
|
||||
@classmethod
|
||||
def new(
|
||||
cls,
|
||||
|
||||
@@ -485,16 +485,20 @@ class ZHAGateway:
|
||||
self, sender, profile, cluster, src_ep, dst_ep, message
|
||||
):
|
||||
"""Handle tasks when a device becomes available."""
|
||||
self.async_update_device(sender)
|
||||
self.async_update_device(sender, available=True)
|
||||
|
||||
@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."""
|
||||
if sender.ieee in self.devices:
|
||||
device = self.devices[sender.ieee]
|
||||
# avoid a race condition during new joins
|
||||
if device.status is DeviceStatus.INITIALIZED:
|
||||
device.update_available(available)
|
||||
else:
|
||||
device.available = available
|
||||
|
||||
async def async_update_device_storage(self):
|
||||
"""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):
|
||||
"""Handle message from a device."""
|
||||
if (
|
||||
not sender.initializing
|
||||
and sender.ieee in zha_gateway.devices
|
||||
sender.ieee in zha_gateway.devices
|
||||
and not zha_gateway.devices[sender.ieee].available
|
||||
):
|
||||
zha_gateway.async_device_became_available(
|
||||
|
||||
@@ -211,7 +211,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
||||
if not self.zha_device.is_mains_powered:
|
||||
# mains powered devices will get real time 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:
|
||||
"""Retrieve latest state."""
|
||||
|
||||
Reference in new issue
Block a user