Home Assistant Unofficial Reference 2024.12.1
atlantic_pass_apc_zone_control.py
Go to the documentation of this file.
1 """Support for Atlantic Pass APC Zone Control."""
2 
3 from typing import cast
4 
5 from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
6 
8  ClimateEntity,
9  ClimateEntityFeature,
10  HVACMode,
11 )
12 from homeassistant.const import UnitOfTemperature
13 
14 from ..coordinator import OverkizDataUpdateCoordinator
15 from ..entity import OverkizEntity
16 
17 OVERKIZ_TO_HVAC_MODE: dict[str, HVACMode] = {
18  OverkizCommandParam.HEATING: HVACMode.HEAT,
19  OverkizCommandParam.DRYING: HVACMode.DRY,
20  OverkizCommandParam.COOLING: HVACMode.COOL,
21  OverkizCommandParam.STOP: HVACMode.OFF,
22 }
23 
24 HVAC_MODE_TO_OVERKIZ = {v: k for k, v in OVERKIZ_TO_HVAC_MODE.items()}
25 
26 
28  """Representation of Atlantic Pass APC Zone Control."""
29 
30  _attr_temperature_unit = UnitOfTemperature.CELSIUS
31  _attr_supported_features = (
32  ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
33  )
34  _enable_turn_on_off_backwards_compatibility = False
35 
36  def __init__(
37  self, device_url: str, coordinator: OverkizDataUpdateCoordinator
38  ) -> None:
39  """Init method."""
40  super().__init__(device_url, coordinator)
41 
42  self._attr_hvac_modes_attr_hvac_modes = [*HVAC_MODE_TO_OVERKIZ]
43 
44  # Cooling is supported by a separate command
45  if self.is_auto_hvac_mode_availableis_auto_hvac_mode_available:
46  self._attr_hvac_modes_attr_hvac_modes.append(HVACMode.AUTO)
47 
48  @property
49  def is_auto_hvac_mode_available(self) -> bool:
50  """Check if auto mode is available on the ZoneControl."""
51 
52  return self.executorexecutor.has_command(
53  OverkizCommand.SET_HEATING_COOLING_AUTO_SWITCH
54  ) and self.executorexecutor.has_state(OverkizState.CORE_HEATING_COOLING_AUTO_SWITCH)
55 
56  @property
57  def hvac_mode(self) -> HVACMode:
58  """Return hvac operation ie. heat, cool mode."""
59 
60  if (
61  self.is_auto_hvac_mode_availableis_auto_hvac_mode_available
62  and cast(
63  str,
64  self.executorexecutor.select_state(
65  OverkizState.CORE_HEATING_COOLING_AUTO_SWITCH
66  ),
67  )
68  == OverkizCommandParam.ON
69  ):
70  return HVACMode.AUTO
71 
72  return OVERKIZ_TO_HVAC_MODE[
73  cast(
74  str, self.executorexecutor.select_state(OverkizState.IO_PASS_APC_OPERATING_MODE)
75  )
76  ]
77 
78  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
79  """Set new target hvac mode."""
80 
81  if self.is_auto_hvac_mode_availableis_auto_hvac_mode_available:
82  await self.executorexecutor.async_execute_command(
83  OverkizCommand.SET_HEATING_COOLING_AUTO_SWITCH,
84  OverkizCommandParam.ON
85  if hvac_mode == HVACMode.AUTO
86  else OverkizCommandParam.OFF,
87  )
88 
89  if hvac_mode == HVACMode.AUTO:
90  return
91 
92  await self.executorexecutor.async_execute_command(
93  OverkizCommand.SET_PASS_APC_OPERATING_MODE, HVAC_MODE_TO_OVERKIZ[hvac_mode]
94  )