1 """Support for the Airzone switch."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from typing
import Any, Final
8 from aioairzone.const
import API_ON, AZD_ON, AZD_ZONES
13 SwitchEntityDescription,
19 from .
import AirzoneConfigEntry
20 from .coordinator
import AirzoneUpdateCoordinator
21 from .entity
import AirzoneEntity, AirzoneZoneEntity
24 @dataclass(frozen=True, kw_only=True)
26 """Class to describe an Airzone switch entity."""
31 ZONE_SWITCH_TYPES: Final[tuple[AirzoneSwitchDescription, ...]] = (
34 device_class=SwitchDeviceClass.SWITCH,
42 entry: AirzoneConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Add Airzone switch from a config_entry."""
46 coordinator = entry.runtime_data
48 added_zones: set[str] = set()
50 def _async_entity_listener() -> None:
51 """Handle additions of switch."""
53 zones_data = coordinator.data.get(AZD_ZONES, {})
54 received_zones = set(zones_data)
55 new_zones = received_zones - added_zones
63 zones_data.get(system_zone_id),
65 for system_zone_id
in new_zones
66 for description
in ZONE_SWITCH_TYPES
67 if description.key
in zones_data.get(system_zone_id)
69 added_zones.update(new_zones)
71 entry.async_on_unload(coordinator.async_add_listener(_async_entity_listener))
72 _async_entity_listener()
76 """Define an Airzone switch."""
78 entity_description: AirzoneSwitchDescription
82 """Update attributes when the coordinator updates."""
88 """Update switch attributes."""
93 """Define an Airzone Zone switch."""
97 coordinator: AirzoneUpdateCoordinator,
98 description: AirzoneSwitchDescription,
101 zone_data: dict[str, Any],
104 super().
__init__(coordinator, entry, system_zone_id, zone_data)
108 f
"{self._attr_unique_id}_{system_zone_id}_{description.key}"
115 """Turn the entity on."""
120 """Turn the entity off."""
Any get_airzone_value(self, str key)
None _async_update_hvac_params(self, dict[str, Any] params)
None _async_update_attrs(self)
None _handle_coordinator_update(self)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, AirzoneUpdateCoordinator coordinator, AirzoneSwitchDescription description, ConfigEntry entry, str system_zone_id, dict[str, Any] zone_data)
None async_setup_entry(HomeAssistant hass, AirzoneConfigEntry entry, AddEntitiesCallback async_add_entities)