Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Support for stiebel_eltron climate platform."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
9  PRESET_ECO,
10  ClimateEntity,
11  ClimateEntityFeature,
12  HVACMode,
13 )
14 from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers.entity_platform import AddEntitiesCallback
17 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
18 
19 from . import DOMAIN as STE_DOMAIN
20 
21 DEPENDENCIES = ["stiebel_eltron"]
22 
23 _LOGGER = logging.getLogger(__name__)
24 
25 PRESET_DAY = "day"
26 PRESET_SETBACK = "setback"
27 PRESET_EMERGENCY = "emergency"
28 
29 SUPPORT_HVAC = [HVACMode.AUTO, HVACMode.HEAT, HVACMode.OFF]
30 SUPPORT_PRESET = [PRESET_ECO, PRESET_DAY, PRESET_EMERGENCY, PRESET_SETBACK]
31 
32 # Mapping STIEBEL ELTRON states to homeassistant states/preset.
33 STE_TO_HA_HVAC = {
34  "AUTOMATIC": HVACMode.AUTO,
35  "MANUAL MODE": HVACMode.HEAT,
36  "STANDBY": HVACMode.AUTO,
37  "DAY MODE": HVACMode.AUTO,
38  "SETBACK MODE": HVACMode.AUTO,
39  "DHW": HVACMode.OFF,
40  "EMERGENCY OPERATION": HVACMode.AUTO,
41 }
42 
43 STE_TO_HA_PRESET = {
44  "STANDBY": PRESET_ECO,
45  "DAY MODE": PRESET_DAY,
46  "SETBACK MODE": PRESET_SETBACK,
47  "EMERGENCY OPERATION": PRESET_EMERGENCY,
48 }
49 
50 HA_TO_STE_HVAC = {
51  HVACMode.AUTO: "AUTOMATIC",
52  HVACMode.HEAT: "MANUAL MODE",
53  HVACMode.OFF: "DHW",
54 }
55 
56 HA_TO_STE_PRESET = {k: i for i, k in STE_TO_HA_PRESET.items()}
57 
58 
60  hass: HomeAssistant,
61  config: ConfigType,
62  add_entities: AddEntitiesCallback,
63  discovery_info: DiscoveryInfoType | None = None,
64 ) -> None:
65  """Set up the StiebelEltron platform."""
66  name = hass.data[STE_DOMAIN]["name"]
67  ste_data = hass.data[STE_DOMAIN]["ste_data"]
68 
69  add_entities([StiebelEltron(name, ste_data)], True)
70 
71 
73  """Representation of a STIEBEL ELTRON heat pump."""
74 
75  _attr_hvac_modes = SUPPORT_HVAC
76  _attr_supported_features = (
77  ClimateEntityFeature.TARGET_TEMPERATURE
78  | ClimateEntityFeature.PRESET_MODE
79  | ClimateEntityFeature.TURN_OFF
80  | ClimateEntityFeature.TURN_ON
81  )
82  _attr_temperature_unit = UnitOfTemperature.CELSIUS
83  _enable_turn_on_off_backwards_compatibility = False
84 
85  def __init__(self, name, ste_data):
86  """Initialize the unit."""
87  self._name_name = name
88  self._target_temperature_target_temperature = None
89  self._current_temperature_current_temperature = None
90  self._current_humidity_current_humidity = None
91  self._operation_operation = None
92  self._filter_alarm_filter_alarm = None
93  self._force_update_force_update = False
94  self._ste_data_ste_data = ste_data
95 
96  def update(self) -> None:
97  """Update unit attributes."""
98  self._ste_data_ste_data.update(no_throttle=self._force_update_force_update)
99  self._force_update_force_update = False
100 
101  self._target_temperature_target_temperature = self._ste_data_ste_data.api.get_target_temp()
102  self._current_temperature_current_temperature = self._ste_data_ste_data.api.get_current_temp()
103  self._current_humidity_current_humidity = self._ste_data_ste_data.api.get_current_humidity()
104  self._filter_alarm_filter_alarm = self._ste_data_ste_data.api.get_filter_alarm_status()
105  self._operation_operation = self._ste_data_ste_data.api.get_operation()
106 
107  _LOGGER.debug(
108  "Update %s, current temp: %s", self._name_name, self._current_temperature_current_temperature
109  )
110 
111  @property
113  """Return device specific state attributes."""
114  return {"filter_alarm": self._filter_alarm_filter_alarm}
115 
116  @property
117  def name(self):
118  """Return the name of the climate device."""
119  return self._name_name
120 
121  # Handle ClimateEntityFeature.TARGET_TEMPERATURE
122 
123  @property
125  """Return the current temperature."""
126  return self._current_temperature_current_temperature
127 
128  @property
130  """Return the temperature we try to reach."""
131  return self._target_temperature_target_temperature
132 
133  @property
135  """Return the supported step of target temperature."""
136  return 0.1
137 
138  @property
139  def min_temp(self):
140  """Return the minimum temperature."""
141  return 10.0
142 
143  @property
144  def max_temp(self):
145  """Return the maximum temperature."""
146  return 30.0
147 
148  @property
149  def current_humidity(self):
150  """Return the current humidity."""
151  return float(f"{self._current_humidity:.1f}")
152 
153  @property
154  def hvac_mode(self) -> HVACMode | None:
155  """Return current operation ie. heat, cool, idle."""
156  return STE_TO_HA_HVAC.get(self._operation_operation)
157 
158  @property
159  def preset_mode(self):
160  """Return the current preset mode, e.g., home, away, temp."""
161  return STE_TO_HA_PRESET.get(self._operation_operation)
162 
163  @property
164  def preset_modes(self):
165  """Return a list of available preset modes."""
166  return SUPPORT_PRESET
167 
168  def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
169  """Set new operation mode."""
170  if self.preset_modepreset_modepreset_mode:
171  return
172  new_mode = HA_TO_STE_HVAC.get(hvac_mode)
173  _LOGGER.debug("set_hvac_mode: %s -> %s", self._operation_operation, new_mode)
174  self._ste_data_ste_data.api.set_operation(new_mode)
175  self._force_update_force_update = True
176 
177  def set_temperature(self, **kwargs: Any) -> None:
178  """Set new target temperature."""
179  target_temperature = kwargs.get(ATTR_TEMPERATURE)
180  if target_temperature is not None:
181  _LOGGER.debug("set_temperature: %s", target_temperature)
182  self._ste_data_ste_data.api.set_target_temp(target_temperature)
183  self._force_update_force_update = True
184 
185  def set_preset_mode(self, preset_mode: str) -> None:
186  """Set new preset mode."""
187  new_mode = HA_TO_STE_PRESET.get(preset_mode)
188  _LOGGER.debug("set_hvac_mode: %s -> %s", self._operation_operation, new_mode)
189  self._ste_data_ste_data.api.set_operation(new_mode)
190  self._force_update_force_update = True
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: climate.py:64