1 """Support for the Airzone climate."""
3 from __future__
import annotations
5 from typing
import Any, Final
7 from aioairzone.common
import OperationAction, OperationMode
8 from aioairzone.const
import (
36 ATTR_TARGET_TEMP_HIGH,
53 from .
import AirzoneConfigEntry
54 from .const
import API_TEMPERATURE_STEP, TEMP_UNIT_LIB_TO_HASS
55 from .coordinator
import AirzoneUpdateCoordinator
56 from .entity
import AirzoneZoneEntity
58 BASE_FAN_SPEEDS: Final[dict[int, str]] = {
62 FAN_SPEED_MAPS: Final[dict[int, dict[int, str]]] = {
74 HVAC_ACTION_LIB_TO_HASS: Final[dict[OperationAction, HVACAction]] = {
75 OperationAction.COOLING: HVACAction.COOLING,
76 OperationAction.DRYING: HVACAction.DRYING,
77 OperationAction.FAN: HVACAction.FAN,
78 OperationAction.HEATING: HVACAction.HEATING,
79 OperationAction.IDLE: HVACAction.IDLE,
80 OperationAction.OFF: HVACAction.OFF,
82 HVAC_MODE_LIB_TO_HASS: Final[dict[OperationMode, HVACMode]] = {
83 OperationMode.STOP: HVACMode.OFF,
84 OperationMode.COOLING: HVACMode.COOL,
85 OperationMode.HEATING: HVACMode.HEAT,
86 OperationMode.FAN: HVACMode.FAN_ONLY,
87 OperationMode.DRY: HVACMode.DRY,
88 OperationMode.AUX_HEATING: HVACMode.HEAT,
89 OperationMode.AUTO: HVACMode.HEAT_COOL,
91 HVAC_MODE_HASS_TO_LIB: Final[dict[HVACMode, OperationMode]] = {
92 HVACMode.OFF: OperationMode.STOP,
93 HVACMode.COOL: OperationMode.COOLING,
94 HVACMode.HEAT: OperationMode.HEATING,
95 HVACMode.FAN_ONLY: OperationMode.FAN,
96 HVACMode.DRY: OperationMode.DRY,
97 HVACMode.HEAT_COOL: OperationMode.AUTO,
103 entry: AirzoneConfigEntry,
104 async_add_entities: AddEntitiesCallback,
106 """Add Airzone climate from a config_entry."""
107 coordinator = entry.runtime_data
109 added_zones: set[str] = set()
111 def _async_entity_listener() -> None:
112 """Handle additions of climate."""
114 zones_data = coordinator.data.get(AZD_ZONES, {})
115 received_zones = set(zones_data)
116 new_zones = received_zones - added_zones
123 zones_data.get(system_zone_id),
125 for system_zone_id
in new_zones
127 added_zones.update(new_zones)
129 entry.async_on_unload(coordinator.async_add_listener(_async_entity_listener))
130 _async_entity_listener()
134 """Define an Airzone sensor."""
137 _speeds: dict[int, str] = {}
138 _speeds_reverse: dict[str, int] = {}
139 _enable_turn_on_off_backwards_compatibility =
False
143 coordinator: AirzoneUpdateCoordinator,
148 """Initialize Airzone climate entity."""
149 super().
__init__(coordinator, entry, system_zone_id, zone_data)
153 ClimateEntityFeature.TARGET_TEMPERATURE
154 | ClimateEntityFeature.TURN_OFF
155 | ClimateEntityFeature.TURN_ON
172 ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
181 max_speed =
max(speeds)
182 if _speeds := FAN_SPEED_MAPS.get(max_speed):
187 self.
_speeds_speeds[speed] = FAN_AUTO
189 self.
_speeds_speeds[speed] = f
"{int(round((speed * 100) / max_speed, 0))}%"
191 self.
_speeds_speeds[1] = FAN_LOW
192 self.
_speeds_speeds[
int(round((max_speed + 1) / 2, 0))] = FAN_MEDIUM
193 self.
_speeds_speeds[max_speed] = FAN_HIGH
199 """Turn the entity on."""
206 """Turn the entity off."""
224 if hvac_mode == HVACMode.OFF:
227 mode = HVAC_MODE_HASS_TO_LIB[hvac_mode]
230 params[API_MODE] = mode
238 f
"Mode can't be changed on slave zone {self.entity_id}"
242 """Set new target temperature."""
244 if ATTR_TEMPERATURE
in kwargs:
245 params[API_SET_POINT] = kwargs[ATTR_TEMPERATURE]
246 if ATTR_TARGET_TEMP_LOW
in kwargs
and ATTR_TARGET_TEMP_HIGH
in kwargs:
247 params[API_COOL_SET_POINT] = kwargs[ATTR_TARGET_TEMP_HIGH]
248 params[API_HEAT_SET_POINT] = kwargs[ATTR_TARGET_TEMP_LOW]
251 if ATTR_HVAC_MODE
in kwargs:
256 """Update attributes when the coordinator updates."""
262 """Update climate attributes."""
None async_set_temperature(self, **Any kwargs)
None async_set_hvac_mode(self, HVACMode hvac_mode)
_attr_target_temperature_step
None async_set_fan_mode(self, str fan_mode)
_attr_target_temperature_low
None __init__(self, AirzoneUpdateCoordinator coordinator, ConfigEntry entry, str system_zone_id, dict zone_data)
None _handle_coordinator_update(self)
None _async_update_attrs(self)
None _set_fan_speeds(self)
None async_turn_off(self)
_attr_current_temperature
_attr_target_temperature_high
Any get_airzone_value(self, str key)
Any get_airzone_value(self, str key)
None _async_update_hvac_params(self, dict[str, Any] params)
ClimateEntityFeature supported_features(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
int|None supported_features(self)
None async_setup_entry(HomeAssistant hass, AirzoneConfigEntry entry, AddEntitiesCallback async_add_entities)
web.Response get(self, web.Request request, str config_key)