Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions homeassistant/components/tradfri/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(
"""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
Expand Down Expand Up @@ -105,7 +104,6 @@ def _refresh(self, device: Device, write_ha: bool = True) -> None:
"""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()

Expand All @@ -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."""
Expand All @@ -128,3 +136,11 @@ def device_info(self) -> DeviceInfo:
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)