Home Assistant Unofficial Reference 2024.12.1
water_heater.py
Go to the documentation of this file.
1 """Support for the Airzone water heater."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, Final
6 
7 from aioairzone.common import HotWaterOperation
8 from aioairzone.const import (
9  API_ACS_ON,
10  API_ACS_POWER_MODE,
11  API_ACS_SET_POINT,
12  AZD_HOT_WATER,
13  AZD_OPERATION,
14  AZD_OPERATIONS,
15  AZD_TEMP,
16  AZD_TEMP_MAX,
17  AZD_TEMP_MIN,
18  AZD_TEMP_SET,
19  AZD_TEMP_UNIT,
20 )
21 
23  STATE_ECO,
24  STATE_PERFORMANCE,
25  WaterHeaterEntity,
26  WaterHeaterEntityFeature,
27 )
28 from homeassistant.config_entries import ConfigEntry
29 from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF
30 from homeassistant.core import HomeAssistant, callback
31 from homeassistant.helpers.entity_platform import AddEntitiesCallback
32 
33 from . import AirzoneConfigEntry
34 from .const import TEMP_UNIT_LIB_TO_HASS
35 from .coordinator import AirzoneUpdateCoordinator
36 from .entity import AirzoneHotWaterEntity
37 
38 OPERATION_LIB_TO_HASS: Final[dict[HotWaterOperation, str]] = {
39  HotWaterOperation.Off: STATE_OFF,
40  HotWaterOperation.On: STATE_ECO,
41  HotWaterOperation.Powerful: STATE_PERFORMANCE,
42 }
43 
44 OPERATION_MODE_TO_DHW_PARAMS: Final[dict[str, dict[str, Any]]] = {
45  STATE_OFF: {
46  API_ACS_ON: 0,
47  },
48  STATE_ECO: {
49  API_ACS_ON: 1,
50  API_ACS_POWER_MODE: 0,
51  },
52  STATE_PERFORMANCE: {
53  API_ACS_ON: 1,
54  API_ACS_POWER_MODE: 1,
55  },
56 }
57 
58 
60  hass: HomeAssistant,
61  entry: AirzoneConfigEntry,
62  async_add_entities: AddEntitiesCallback,
63 ) -> None:
64  """Add Airzone Water Heater from a config_entry."""
65  coordinator = entry.runtime_data
66  if AZD_HOT_WATER in coordinator.data:
67  async_add_entities([AirzoneWaterHeater(coordinator, entry)])
68 
69 
71  """Define an Airzone Water Heater."""
72 
73  _attr_name = None
74  _attr_supported_features = (
75  WaterHeaterEntityFeature.TARGET_TEMPERATURE
76  | WaterHeaterEntityFeature.ON_OFF
77  | WaterHeaterEntityFeature.OPERATION_MODE
78  )
79 
80  def __init__(
81  self,
82  coordinator: AirzoneUpdateCoordinator,
83  entry: ConfigEntry,
84  ) -> None:
85  """Initialize Airzone water heater entity."""
86  super().__init__(coordinator, entry)
87 
88  self._attr_unique_id_attr_unique_id_attr_unique_id = f"{self._attr_unique_id}_dhw"
89  self._attr_operation_list_attr_operation_list = [
90  OPERATION_LIB_TO_HASS[operation]
91  for operation in self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_OPERATIONS)
92  ]
93  self._attr_temperature_unit_attr_temperature_unit = TEMP_UNIT_LIB_TO_HASS[
94  self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_TEMP_UNIT)
95  ]
96 
97  self._async_update_attrs_async_update_attrs()
98 
99  async def async_turn_off(self, **kwargs: Any) -> None:
100  """Turn the water heater off."""
101  await self._async_update_dhw_params_async_update_dhw_params({API_ACS_ON: 0})
102 
103  async def async_turn_on(self, **kwargs: Any) -> None:
104  """Turn the water heater off."""
105  await self._async_update_dhw_params_async_update_dhw_params({API_ACS_ON: 1})
106 
107  async def async_set_operation_mode(self, operation_mode: str) -> None:
108  """Set new target operation mode."""
109  params = OPERATION_MODE_TO_DHW_PARAMS.get(operation_mode, {})
110  await self._async_update_dhw_params_async_update_dhw_params(params)
111 
112  async def async_set_temperature(self, **kwargs: Any) -> None:
113  """Set new target temperature."""
114  params: dict[str, Any] = {}
115  if ATTR_TEMPERATURE in kwargs:
116  params[API_ACS_SET_POINT] = kwargs[ATTR_TEMPERATURE]
117  await self._async_update_dhw_params_async_update_dhw_params(params)
118 
119  @callback
120  def _handle_coordinator_update(self) -> None:
121  """Update attributes when the coordinator updates."""
122  self._async_update_attrs_async_update_attrs()
124 
125  @callback
126  def _async_update_attrs(self) -> None:
127  """Update water heater attributes."""
128  self._attr_current_temperature_attr_current_temperature = self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_TEMP)
129  self._attr_current_operation_attr_current_operation = OPERATION_LIB_TO_HASS[
130  self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_OPERATION)
131  ]
132  self._attr_max_temp_attr_max_temp = self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_TEMP_MAX)
133  self._attr_min_temp_attr_min_temp = self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_TEMP_MIN)
134  self._attr_target_temperature_attr_target_temperature = self.get_airzone_valueget_airzone_valueget_airzone_value(AZD_TEMP_SET)
None _async_update_dhw_params(self, dict[str, Any] params)
Definition: entity.py:113
None __init__(self, AirzoneUpdateCoordinator coordinator, ConfigEntry entry)
Definition: water_heater.py:84
None async_setup_entry(HomeAssistant hass, AirzoneConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: water_heater.py:63