1 """Support for Tado sensors for each zone."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
20 from .
import TadoConfigEntry
22 SIGNAL_TADO_UPDATE_RECEIVED,
23 TYPE_AIR_CONDITIONING,
29 from .entity
import TadoDeviceEntity, TadoZoneEntity
30 from .tado_connector
import TadoConnector
32 _LOGGER = logging.getLogger(__name__)
35 @dataclass(frozen=True, kw_only=True)
37 """Describes Tado binary sensor entity."""
39 state_fn: Callable[[Any], bool]
41 attributes_fn: Callable[[Any], dict[Any, StateType]] |
None =
None
46 state_fn=
lambda data: data[
"batteryState"] ==
"LOW",
47 device_class=BinarySensorDeviceClass.BATTERY,
50 key=
"connection state",
51 translation_key=
"connection_state",
52 state_fn=
lambda data: data.get(
"connectionState", {}).
get(
"value",
False),
53 device_class=BinarySensorDeviceClass.CONNECTIVITY,
57 state_fn=
lambda data: data.power ==
"ON",
58 device_class=BinarySensorDeviceClass.POWER,
62 state_fn=
lambda data: data.link ==
"ONLINE",
63 device_class=BinarySensorDeviceClass.CONNECTIVITY,
67 translation_key=
"overlay",
68 state_fn=
lambda data: data.overlay_active,
69 attributes_fn=
lambda data: (
70 {
"termination": data.overlay_termination_type}
if data.overlay_active
else {}
72 device_class=BinarySensorDeviceClass.POWER,
76 state_fn=
lambda data: bool(data.open_window
or data.open_window_detected),
77 attributes_fn=
lambda data: data.open_window_attr,
78 device_class=BinarySensorDeviceClass.WINDOW,
82 translation_key=
"early_start",
83 state_fn=
lambda data: data.preparation,
84 device_class=BinarySensorDeviceClass.POWER,
89 BATTERY_STATE_ENTITY_DESCRIPTION,
90 CONNECTION_STATE_ENTITY_DESCRIPTION,
93 CONNECTION_STATE_ENTITY_DESCRIPTION,
99 POWER_ENTITY_DESCRIPTION,
100 LINK_ENTITY_DESCRIPTION,
101 OVERLAY_ENTITY_DESCRIPTION,
102 OPEN_WINDOW_ENTITY_DESCRIPTION,
103 EARLY_START_ENTITY_DESCRIPTION,
105 TYPE_AIR_CONDITIONING: [
106 POWER_ENTITY_DESCRIPTION,
107 LINK_ENTITY_DESCRIPTION,
108 OVERLAY_ENTITY_DESCRIPTION,
109 OPEN_WINDOW_ENTITY_DESCRIPTION,
112 POWER_ENTITY_DESCRIPTION,
113 LINK_ENTITY_DESCRIPTION,
114 OVERLAY_ENTITY_DESCRIPTION,
120 hass: HomeAssistant, entry: TadoConfigEntry, async_add_entities: AddEntitiesCallback
122 """Set up the Tado sensor platform."""
124 tado = entry.runtime_data
125 devices = tado.devices
127 entities: list[BinarySensorEntity] = []
130 for device
in devices:
131 if "batteryState" in device:
132 device_type = TYPE_BATTERY
134 device_type = TYPE_POWER
139 for entity_description
in DEVICE_SENSORS[device_type]
145 zone_type = zone[
"type"]
146 if zone_type
not in ZONE_SENSORS:
147 _LOGGER.warning(
"Unknown zone type skipped: %s", zone_type)
153 for entity_description
in ZONE_SENSORS[zone_type]
161 """Representation of a tado Sensor."""
163 entity_description: TadoBinarySensorEntityDescription
168 device_info: dict[str, Any],
169 entity_description: TadoBinarySensorEntityDescription,
171 """Initialize of the Tado Sensor."""
177 f
"{entity_description.key} {self.device_id} {tado.home_id}"
181 """Register for sensor updates."""
185 SIGNAL_TADO_UPDATE_RECEIVED.format(
195 """Update and write state."""
201 """Handle update callbacks."""
215 """Representation of a tado Sensor."""
217 entity_description: TadoBinarySensorEntityDescription
224 entity_description: TadoBinarySensorEntityDescription,
226 """Initialize of the Tado Sensor."""
229 super().
__init__(zone_name, tado.home_id, zone_id)
231 self.
_attr_unique_id_attr_unique_id = f
"{entity_description.key} {zone_id} {tado.home_id}"
234 """Register for sensor updates."""
238 SIGNAL_TADO_UPDATE_RECEIVED.format(
248 """Update and write state."""
254 """Handle update callbacks."""
256 tado_zone_data = self.
_tado_tado.data[
"zone"][self.
zone_idzone_id]
_attr_extra_state_attributes
None async_added_to_hass(self)
None _async_update_device_data(self)
None __init__(self, TadoConnector tado, dict[str, Any] device_info, TadoBinarySensorEntityDescription entity_description)
None _async_update_callback(self)
None async_added_to_hass(self)
None _async_update_zone_data(self)
None _async_update_callback(self)
None __init__(self, TadoConnector tado, str zone_name, int zone_id, TadoBinarySensorEntityDescription entity_description)
_attr_extra_state_attributes
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, TadoConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)