Home Assistant Unofficial Reference 2024.12.1
valve_heating_temperature_interface.py
Go to the documentation of this file.
1 """Support for ValveHeatingTemperatureInterface."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, cast
6 
7 from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
8 
10  PRESET_AWAY,
11  PRESET_COMFORT,
12  PRESET_ECO,
13  PRESET_NONE,
14  ClimateEntity,
15  ClimateEntityFeature,
16  HVACAction,
17  HVACMode,
18  UnitOfTemperature,
19 )
20 from homeassistant.const import ATTR_TEMPERATURE
21 
22 from ..const import DOMAIN
23 from ..coordinator import OverkizDataUpdateCoordinator
24 from ..entity import OverkizEntity
25 
26 PRESET_MANUAL = "manual"
27 PRESET_FROST_PROTECTION = "frost_protection"
28 
29 OVERKIZ_TO_HVAC_ACTION: dict[str, HVACAction] = {
30  OverkizCommandParam.OPEN: HVACAction.HEATING,
31  OverkizCommandParam.CLOSED: HVACAction.IDLE,
32 }
33 
34 OVERKIZ_TO_PRESET_MODE: dict[str, str] = {
35  OverkizCommandParam.GEOFENCING_MODE: PRESET_NONE,
36  OverkizCommandParam.SUDDEN_DROP_MODE: PRESET_NONE,
37  OverkizCommandParam.AWAY: PRESET_AWAY,
38  OverkizCommandParam.COMFORT: PRESET_COMFORT,
39  OverkizCommandParam.ECO: PRESET_ECO,
40  OverkizCommandParam.FROSTPROTECTION: PRESET_FROST_PROTECTION,
41  OverkizCommandParam.MANUAL: PRESET_MANUAL,
42 }
43 PRESET_MODE_TO_OVERKIZ = {v: k for k, v in OVERKIZ_TO_PRESET_MODE.items()}
44 
45 TEMPERATURE_SENSOR_DEVICE_INDEX = 2
46 
47 
49  """Representation of Valve Heating Temperature Interface device."""
50 
51  _attr_hvac_mode = HVACMode.HEAT
52  _attr_hvac_modes = [HVACMode.HEAT]
53  _attr_preset_modes = [*PRESET_MODE_TO_OVERKIZ]
54  _attr_supported_features = (
55  ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
56  )
57  _attr_temperature_unit = UnitOfTemperature.CELSIUS
58  _attr_translation_key = DOMAIN
59  _enable_turn_on_off_backwards_compatibility = False
60 
61  def __init__(
62  self, device_url: str, coordinator: OverkizDataUpdateCoordinator
63  ) -> None:
64  """Init method."""
65  super().__init__(device_url, coordinator)
66  self.temperature_devicetemperature_device = self.executorexecutor.linked_device(
67  TEMPERATURE_SENSOR_DEVICE_INDEX
68  )
69 
70  self._attr_min_temp_attr_min_temp = cast(
71  float, self.executorexecutor.select_state(OverkizState.CORE_MIN_SETPOINT)
72  )
73  self._attr_max_temp_attr_max_temp = cast(
74  float, self.executorexecutor.select_state(OverkizState.CORE_MAX_SETPOINT)
75  )
76 
77  @property
78  def hvac_action(self) -> HVACAction:
79  """Return the current running hvac operation."""
80  return OVERKIZ_TO_HVAC_ACTION[
81  cast(str, self.executorexecutor.select_state(OverkizState.CORE_OPEN_CLOSED_VALVE))
82  ]
83 
84  @property
85  def target_temperature(self) -> float:
86  """Return the temperature."""
87  return cast(
88  float, self.executorexecutor.select_state(OverkizState.CORE_TARGET_TEMPERATURE)
89  )
90 
91  @property
92  def current_temperature(self) -> float | None:
93  """Return the current temperature."""
94  if self.temperature_devicetemperature_device is not None and (
95  temperature := self.temperature_devicetemperature_device.states[OverkizState.CORE_TEMPERATURE]
96  ):
97  return temperature.value_as_float
98 
99  return None
100 
101  async def async_set_temperature(self, **kwargs: Any) -> None:
102  """Set new temperature."""
103  temperature = kwargs[ATTR_TEMPERATURE]
104 
105  await self.executorexecutor.async_execute_command(
106  OverkizCommand.SET_DEROGATION,
107  float(temperature),
108  OverkizCommandParam.FURTHER_NOTICE,
109  )
110 
111  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
112  """Set new target hvac mode."""
113  return
114 
115  @property
116  def preset_mode(self) -> str:
117  """Return the current preset mode, e.g., home, away, temp."""
118  return OVERKIZ_TO_PRESET_MODE[
119  cast(
120  str, self.executorexecutor.select_state(OverkizState.IO_DEROGATION_HEATING_MODE)
121  )
122  ]
123 
124  async def async_set_preset_mode(self, preset_mode: str) -> None:
125  """Set new preset mode."""
126 
127  # If we want to switch to manual mode via a preset, we need to pass in a temperature
128  # Manual mode will be on automatically if an user sets a temperature
129  if preset_mode == PRESET_MANUAL:
130  if current_temperature := self.current_temperaturecurrent_temperaturecurrent_temperature:
131  await self.executorexecutor.async_execute_command(
132  OverkizCommand.SET_DEROGATION,
133  current_temperature,
134  OverkizCommandParam.FURTHER_NOTICE,
135  )
136  else:
137  await self.executorexecutor.async_execute_command(
138  OverkizCommand.SET_DEROGATION,
139  PRESET_MODE_TO_OVERKIZ[preset_mode],
140  OverkizCommandParam.FURTHER_NOTICE,
141  )