Blacklist availability check for a light at startup in Hue integration (#61737)

pull/61746/head
Marcel van der Veldt 2021-12-14 01:23:32 +01:00 committed by GitHub
parent eb345bfdf1
commit 89a6640b82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -47,6 +47,20 @@ 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
# 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 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:
@ -98,13 +112,12 @@ class HueBaseEntity(Entity):
def available(self) -> bool: def available(self) -> bool:
"""Return entity availability.""" """Return entity availability."""
if self.device is None: if self.device is None:
# devices without a device attached should be always available # entities without a device attached should be always available
return True return True
if self.resource.type == ResourceTypes.ZIGBEE_CONNECTIVITY: if self.resource.type == ResourceTypes.ZIGBEE_CONNECTIVITY:
# the zigbee connectivity sensor itself should be always available # the zigbee connectivity sensor itself should be always available
return True return True
if self.device.product_data.manufacturer_name != "Signify Netherlands B.V.": if self._ignore_availability:
# availability status for non-philips brand lights is unreliable
return True return True
if zigbee := self.bridge.api.devices.get_zigbee_connectivity(self.device.id): if zigbee := self.bridge.api.devices.get_zigbee_connectivity(self.device.id):
# all device-attached entities get availability from the zigbee connectivity # all device-attached entities get availability from the zigbee connectivity