Change Hue availability blacklist logic a bit (#62446)

pull/62455/head
Marcel van der Veldt 2021-12-21 01:09:14 +01:00 committed by GitHub
parent aaac1d4c5a
commit 92454e3ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 14 deletions

View File

@ -47,20 +47,9 @@ class HueBaseEntity(Entity):
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.device.id)}, identifiers={(DOMAIN, self.device.id)},
) )
# some (3th party) Hue lights report their connection status incorrectly # used for availability workaround
# causing the zigbee availability to report as disconnected while in fact self._ignore_availability = None
# it can be controlled. Although this is in fact something the device manufacturer self._last_state = None
# should fix, we work around it here. If the light is reported unavailable at
# startup, we ignore the availability status of the zigbee connection
self._ignore_availability = False
if self.device is None:
return
if zigbee := self.bridge.api.devices.get_zigbee_connectivity(self.device.id):
self._ignore_availability = (
# Official Hue lights are reliable
self.device.product_data.manufacturer_name != "Signify Netherlands B.V."
and zigbee.status != ConnectivityServiceStatus.CONNECTED
)
@property @property
def name(self) -> str: def name(self) -> str:
@ -82,6 +71,7 @@ class HueBaseEntity(Entity):
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Call when entity is added.""" """Call when entity is added."""
self._check_availability_workaround()
# Add value_changed callbacks. # Add value_changed callbacks.
self.async_on_remove( self.async_on_remove(
self.controller.subscribe( self.controller.subscribe(
@ -140,5 +130,50 @@ class HueBaseEntity(Entity):
ent_reg.async_remove(self.entity_id) ent_reg.async_remove(self.entity_id)
else: else:
self.logger.debug("Received status update for %s", self.entity_id) self.logger.debug("Received status update for %s", self.entity_id)
self._check_availability_workaround()
self.on_update() self.on_update()
self.async_write_ha_state() self.async_write_ha_state()
@callback
def _check_availability_workaround(self):
"""Check availability of the device."""
if self.resource.type != ResourceTypes.LIGHT:
return
if self._ignore_availability is not None:
# already processed
return
cur_state = self.resource.on.on
if self._last_state is None:
self._last_state = cur_state
return
# some (3th party) Hue lights report their connection status incorrectly
# causing the zigbee availability to report as disconnected while in fact
# it can be controlled. Although this is in fact something the device manufacturer
# should fix, we work around it here. If the light is reported unavailable
# by the zigbee connectivity but the state changesm its considered as a
# malfunctioning device and we report it.
# while the user should actually fix this issue instead of ignoring it, we
# ignore the availability for this light from this point.
if zigbee := self.bridge.api.devices.get_zigbee_connectivity(self.device.id):
if (
self._last_state != cur_state
and zigbee.status != ConnectivityServiceStatus.CONNECTED
):
# the device state changed from on->off or off->on
# while it was reported as not connected!
self.logger.warning(
"Light %s changed state while reported as disconnected. "
"This is an indicator that routing is not working properly for this device. "
"Home Assistant will ignore availability for this light from now on. "
"Device details: %s - %s (%s) fw: %s",
self.name,
self.device.product_data.manufacturer_name,
self.device.product_data.product_name,
self.device.product_data.model_id,
self.device.product_data.software_version,
)
# do we want to store this in some persistent storage?
self._ignore_availability = True
else:
self._ignore_availability = False
self._last_state = cur_state