1 """Support for the Airzone sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from typing
import Any, Final
8 from aioairzone.const
import (
19 BinarySensorDeviceClass,
21 BinarySensorEntityDescription,
28 from .
import AirzoneConfigEntry
29 from .coordinator
import AirzoneUpdateCoordinator
30 from .entity
import AirzoneEntity, AirzoneSystemEntity, AirzoneZoneEntity
33 @dataclass(frozen=True)
35 """A class that describes airzone binary sensor entities."""
37 attributes: dict[str, str] |
None =
None
40 SYSTEM_BINARY_SENSOR_TYPES: Final[tuple[AirzoneBinarySensorEntityDescription, ...]] = (
45 device_class=BinarySensorDeviceClass.PROBLEM,
46 entity_category=EntityCategory.DIAGNOSTIC,
51 ZONE_BINARY_SENSOR_TYPES: Final[tuple[AirzoneBinarySensorEntityDescription, ...]] = (
53 device_class=BinarySensorDeviceClass.RUNNING,
55 translation_key=
"air_demand",
58 device_class=BinarySensorDeviceClass.BATTERY,
62 device_class=BinarySensorDeviceClass.RUNNING,
64 translation_key=
"floor_demand",
70 device_class=BinarySensorDeviceClass.PROBLEM,
71 entity_category=EntityCategory.DIAGNOSTIC,
79 entry: AirzoneConfigEntry,
80 async_add_entities: AddEntitiesCallback,
82 """Add Airzone binary sensors from a config_entry."""
83 coordinator = entry.runtime_data
85 added_systems: set[str] = set()
86 added_zones: set[str] = set()
88 def _async_entity_listener() -> None:
89 """Handle additions of binary sensors."""
91 entities: list[AirzoneBinarySensor] = []
93 systems_data = coordinator.data.get(AZD_SYSTEMS, {})
94 received_systems = set(systems_data)
95 new_systems = received_systems - added_systems
103 systems_data.get(system_id),
105 for system_id
in new_systems
106 for description
in SYSTEM_BINARY_SENSOR_TYPES
107 if description.key
in systems_data.get(system_id)
109 added_systems.update(new_systems)
111 zones_data = coordinator.data.get(AZD_ZONES, {})
112 received_zones = set(zones_data)
113 new_zones = received_zones - added_zones
121 zones_data.get(system_zone_id),
123 for system_zone_id
in new_zones
124 for description
in ZONE_BINARY_SENSOR_TYPES
125 if description.key
in zones_data.get(system_zone_id)
127 added_zones.update(new_zones)
131 entry.async_on_unload(coordinator.async_add_listener(_async_entity_listener))
132 _async_entity_listener()
136 """Define an Airzone binary sensor."""
138 entity_description: AirzoneBinarySensorEntityDescription
142 """Update attributes when the coordinator updates."""
148 """Update binary sensor attributes."""
150 if self.entity_description.attributes:
153 for key, val
in self.entity_description.attributes.items()
158 """Define an Airzone System binary sensor."""
162 coordinator: AirzoneUpdateCoordinator,
163 description: AirzoneBinarySensorEntityDescription,
166 system_data: dict[str, Any],
169 super().
__init__(coordinator, entry, system_data)
176 """Define an Airzone Zone binary sensor."""
180 coordinator: AirzoneUpdateCoordinator,
181 description: AirzoneBinarySensorEntityDescription,
184 zone_data: dict[str, Any],
187 super().
__init__(coordinator, entry, system_zone_id, zone_data)
190 f
"{self._attr_unique_id}_{system_zone_id}_{description.key}"
None _handle_coordinator_update(self)
None _async_update_attrs(self)
_attr_extra_state_attributes
None __init__(self, AirzoneUpdateCoordinator coordinator, AirzoneBinarySensorEntityDescription description, ConfigEntry entry, str system_id, dict[str, Any] system_data)
None __init__(self, AirzoneUpdateCoordinator coordinator, AirzoneBinarySensorEntityDescription description, ConfigEntry entry, str system_zone_id, dict[str, Any] zone_data)
Any get_airzone_value(self, str key)
None async_setup_entry(HomeAssistant hass, AirzoneConfigEntry entry, AddEntitiesCallback async_add_entities)