Home Assistant Unofficial Reference 2024.12.1
atlantic_heat_recovery_ventilation.py
Go to the documentation of this file.
1 """Support for AtlanticHeatRecoveryVentilation."""
2 
3 from __future__ import annotations
4 
5 from typing import cast
6 
7 from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
8 
10  FAN_AUTO,
11  ClimateEntity,
12  ClimateEntityFeature,
13  HVACMode,
14 )
15 from homeassistant.const import UnitOfTemperature
16 
17 from ..const import DOMAIN
18 from ..coordinator import OverkizDataUpdateCoordinator
19 from ..entity import OverkizEntity
20 
21 FAN_BOOST = "home_boost"
22 FAN_KITCHEN = "kitchen_boost"
23 FAN_AWAY = "away"
24 FAN_BYPASS = "bypass_boost"
25 
26 PRESET_AUTO = "auto"
27 PRESET_PROG = "prog"
28 PRESET_MANUAL = "manual"
29 
30 OVERKIZ_TO_FAN_MODES: dict[str, str] = {
31  OverkizCommandParam.AUTO: FAN_AUTO,
32  OverkizCommandParam.AWAY: FAN_AWAY,
33  OverkizCommandParam.BOOST: FAN_BOOST,
34  OverkizCommandParam.HIGH: FAN_KITCHEN,
35  "": FAN_BYPASS,
36 }
37 
38 FAN_MODES_TO_OVERKIZ = {v: k for k, v in OVERKIZ_TO_FAN_MODES.items()}
39 
40 TEMPERATURE_SENSOR_DEVICE_INDEX = 4
41 
42 
44  """Representation of a AtlanticHeatRecoveryVentilation device."""
45 
46  _attr_fan_modes = [*FAN_MODES_TO_OVERKIZ]
47  _attr_hvac_mode = HVACMode.FAN_ONLY
48  _attr_hvac_modes = [HVACMode.FAN_ONLY]
49  _attr_preset_modes = [PRESET_AUTO, PRESET_PROG, PRESET_MANUAL]
50  _attr_temperature_unit = UnitOfTemperature.CELSIUS
51  _attr_supported_features = (
52  ClimateEntityFeature.PRESET_MODE
53  | ClimateEntityFeature.FAN_MODE
54  | ClimateEntityFeature.TURN_OFF
55  | ClimateEntityFeature.TURN_ON
56  )
57  _attr_translation_key = DOMAIN
58  _enable_turn_on_off_backwards_compatibility = False
59 
60  def __init__(
61  self, device_url: str, coordinator: OverkizDataUpdateCoordinator
62  ) -> None:
63  """Init method."""
64  super().__init__(device_url, coordinator)
65  self.temperature_devicetemperature_device = self.executorexecutor.linked_device(
66  TEMPERATURE_SENSOR_DEVICE_INDEX
67  )
68 
69  @property
70  def current_temperature(self) -> float | None:
71  """Return the current temperature."""
72  if self.temperature_devicetemperature_device is not None and (
73  temperature := self.temperature_devicetemperature_device.states[OverkizState.CORE_TEMPERATURE]
74  ):
75  return cast(float, temperature.value)
76 
77  return None
78 
79  async def async_set_hvac_mode(self, hvac_mode: str) -> None:
80  """Not implemented since there is only one hvac_mode."""
81 
82  @property
83  def preset_mode(self) -> str | None:
84  """Return the current preset mode."""
85  ventilation_configuration = self.executorexecutor.select_state(
86  OverkizState.IO_VENTILATION_CONFIGURATION_MODE
87  )
88 
89  if ventilation_configuration == OverkizCommandParam.COMFORT:
90  return PRESET_AUTO
91 
92  if ventilation_configuration == OverkizCommandParam.STANDARD:
93  return PRESET_MANUAL
94 
95  ventilation_mode = cast(
96  dict, self.executorexecutor.select_state(OverkizState.IO_VENTILATION_MODE)
97  )
98  prog = ventilation_mode.get(OverkizCommandParam.PROG)
99 
100  if prog == OverkizCommandParam.ON:
101  return PRESET_PROG
102 
103  return None
104 
105  async def async_set_preset_mode(self, preset_mode: str) -> None:
106  """Set the preset mode of the fan."""
107  if preset_mode == PRESET_AUTO:
108  await self.executorexecutor.async_execute_command(
109  OverkizCommand.SET_VENTILATION_CONFIGURATION_MODE,
110  OverkizCommandParam.COMFORT,
111  )
112  await self._set_ventilation_mode_set_ventilation_mode(prog=OverkizCommandParam.OFF)
113 
114  if preset_mode == PRESET_PROG:
115  await self.executorexecutor.async_execute_command(
116  OverkizCommand.SET_VENTILATION_CONFIGURATION_MODE,
117  OverkizCommandParam.STANDARD,
118  )
119  await self._set_ventilation_mode_set_ventilation_mode(prog=OverkizCommandParam.ON)
120 
121  if preset_mode == PRESET_MANUAL:
122  await self.executorexecutor.async_execute_command(
123  OverkizCommand.SET_VENTILATION_CONFIGURATION_MODE,
124  OverkizCommandParam.STANDARD,
125  )
126  await self._set_ventilation_mode_set_ventilation_mode(prog=OverkizCommandParam.OFF)
127 
128  await self.executorexecutor.async_execute_command(
129  OverkizCommand.REFRESH_VENTILATION_STATE,
130  )
131  await self.executorexecutor.async_execute_command(
132  OverkizCommand.REFRESH_VENTILATION_CONFIGURATION_MODE,
133  )
134 
135  @property
136  def fan_mode(self) -> str | None:
137  """Return the fan setting."""
138  ventilation_mode = cast(
139  dict, self.executorexecutor.select_state(OverkizState.IO_VENTILATION_MODE)
140  )
141  cooling = ventilation_mode.get(OverkizCommandParam.COOLING)
142 
143  if cooling == OverkizCommandParam.ON:
144  return FAN_BYPASS
145 
146  return OVERKIZ_TO_FAN_MODES[
147  cast(str, self.executorexecutor.select_state(OverkizState.IO_AIR_DEMAND_MODE))
148  ]
149 
150  async def async_set_fan_mode(self, fan_mode: str) -> None:
151  """Set new target fan mode."""
152  if fan_mode == FAN_BYPASS:
153  await self.executorexecutor.async_execute_command(
154  OverkizCommand.SET_AIR_DEMAND_MODE, OverkizCommandParam.AUTO
155  )
156  await self._set_ventilation_mode_set_ventilation_mode(cooling=OverkizCommandParam.ON)
157  else:
158  await self._set_ventilation_mode_set_ventilation_mode(cooling=OverkizCommandParam.OFF)
159  await self.executorexecutor.async_execute_command(
160  OverkizCommand.SET_AIR_DEMAND_MODE, FAN_MODES_TO_OVERKIZ[fan_mode]
161  )
162 
163  await self.executorexecutor.async_execute_command(
164  OverkizCommand.REFRESH_VENTILATION_STATE,
165  )
166 
168  self,
169  cooling: str | None = None,
170  prog: str | None = None,
171  ) -> None:
172  """Execute ventilation mode command with all parameters."""
173  ventilation_mode = cast(
174  dict, self.executorexecutor.select_state(OverkizState.IO_VENTILATION_MODE)
175  )
176 
177  if cooling:
178  ventilation_mode[OverkizCommandParam.COOLING] = cooling
179 
180  if prog:
181  ventilation_mode[OverkizCommandParam.PROG] = prog
182 
183  await self.executorexecutor.async_execute_command(
184  OverkizCommand.SET_VENTILATION_MODE, ventilation_mode
185  )