1 """Support for SwitchBee entity."""
4 from typing
import cast
6 from switchbee
import SWITCHBEE_BRAND
7 from switchbee.device
import DeviceType, SwitchBeeBaseDevice
12 from .const
import DOMAIN
13 from .coordinator
import SwitchBeeCoordinator
15 _LOGGER = logging.getLogger(__name__)
19 CoordinatorEntity[SwitchBeeCoordinator]
21 """Representation of a Switchbee entity."""
23 _attr_has_entity_name =
True
28 coordinator: SwitchBeeCoordinator,
30 """Initialize the Switchbee entity."""
33 self._attr_name = device.name
34 self._attr_unique_id = f
"{coordinator.unique_id}-{device.id}"
38 SwitchBeeEntity[_DeviceTypeT]
40 """Representation of a Switchbee device entity."""
45 coordinator: SwitchBeeCoordinator,
47 """Initialize the Switchbee device."""
48 super().
__init__(device, coordinator)
49 self._is_online: bool =
True
51 device.id
if device.type == DeviceType.Thermostat
else device.unit_id
58 f
"{identifier}-{coordinator.unique_id}",
61 manufacturer=SWITCHBEE_BRAND,
62 model=coordinator.api.module_display(device.unit_id),
63 suggested_area=device.zone,
66 f
"{coordinator.api.name} ({coordinator.api.unique_id})",
72 """Return True if entity is available."""
73 return self._is_online
and super().available
76 """Check if the device was online (now offline), log message and mark it as Unavailable."""
81 "%s device is not responding, check the status in the SwitchBee"
86 self._is_online =
False
89 """Check if the device was offline (now online) and bring it back."""
90 if not self._is_online:
92 "%s device is now responding",
95 self._is_online =
True
98 return cast(_DeviceTypeT, self.coordinator.data[self._device.id])
None _check_if_became_offline(self)
_DeviceTypeT _get_coordinator_device(self)
None _check_if_became_online(self)
None __init__(self, _DeviceTypeT device, SwitchBeeCoordinator coordinator)