From 933ad5ae49b752c1147cd2e25563920d32cfc978 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sat, 6 Nov 2021 16:46:51 +0100 Subject: [PATCH] Fix tradfri group reachable access (#59217) --- .../components/tradfri/base_class.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tradfri/base_class.py b/homeassistant/components/tradfri/base_class.py index a54c9f7d500..8a7cc6a2f4a 100644 --- a/homeassistant/components/tradfri/base_class.py +++ b/homeassistant/components/tradfri/base_class.py @@ -60,7 +60,6 @@ class TradfriBaseClass(Entity): """Initialize a device.""" self._api = handle_error(api) self._attr_name = device.name - self._attr_available = device.reachable self._device: Device = device self._device_control: BlindControl | LightControl | SocketControl | SignalRepeaterControl | AirPurifierControl | None = ( None @@ -105,7 +104,6 @@ class TradfriBaseClass(Entity): """Refresh the device data.""" self._device = device self._attr_name = device.name - self._attr_available = device.reachable if write_ha: self.async_write_ha_state() @@ -116,6 +114,16 @@ class TradfriBaseDevice(TradfriBaseClass): All devices should inherit from this class. """ + def __init__( + self, + device: Device, + api: Callable[[Command | list[Command]], Any], + gateway_id: str, + ) -> None: + """Initialize a device.""" + self._attr_available = device.reachable + super().__init__(device, api, gateway_id) + @property def device_info(self) -> DeviceInfo: """Return the device info.""" @@ -128,3 +136,11 @@ class TradfriBaseDevice(TradfriBaseClass): sw_version=info.firmware_version, via_device=(DOMAIN, self._gateway_id), ) + + def _refresh(self, device: Device, write_ha: bool = True) -> None: + """Refresh the device data.""" + # The base class _refresh cannot be used, because + # there are devices (group) that do not have .reachable + # so set _attr_available here and let the base class do the rest. + self._attr_available = device.reachable + super()._refresh(device, write_ha)