Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Platform for Roth Touchline floor heating controller."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, NamedTuple
6 
7 from pytouchline import PyTouchline
8 import voluptuous as vol
9 
11  PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA,
12  ClimateEntity,
13  ClimateEntityFeature,
14  HVACMode,
15 )
16 from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, UnitOfTemperature
17 from homeassistant.core import HomeAssistant
19 from homeassistant.helpers.entity_platform import AddEntitiesCallback
20 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
21 
22 
23 class PresetMode(NamedTuple):
24  """Settings for preset mode."""
25 
26  mode: int
27  program: int
28 
29 
30 PRESET_MODES = {
31  "Normal": PresetMode(mode=0, program=0),
32  "Night": PresetMode(mode=1, program=0),
33  "Holiday": PresetMode(mode=2, program=0),
34  "Pro 1": PresetMode(mode=0, program=1),
35  "Pro 2": PresetMode(mode=0, program=2),
36  "Pro 3": PresetMode(mode=0, program=3),
37 }
38 
39 TOUCHLINE_HA_PRESETS = {
40  (settings.mode, settings.program): preset
41  for preset, settings in PRESET_MODES.items()
42 }
43 
44 PLATFORM_SCHEMA = CLIMATE_PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string})
45 
46 
48  hass: HomeAssistant,
49  config: ConfigType,
50  add_entities: AddEntitiesCallback,
51  discovery_info: DiscoveryInfoType | None = None,
52 ) -> None:
53  """Set up the Touchline devices."""
54 
55  host = config[CONF_HOST]
56  py_touchline = PyTouchline()
57  number_of_devices = int(py_touchline.get_number_of_devices(host))
59  (Touchline(PyTouchline(device_id)) for device_id in range(number_of_devices)),
60  True,
61  )
62 
63 
65  """Representation of a Touchline device."""
66 
67  _attr_hvac_mode = HVACMode.HEAT
68  _attr_hvac_modes = [HVACMode.HEAT]
69  _attr_supported_features = (
70  ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
71  )
72  _attr_temperature_unit = UnitOfTemperature.CELSIUS
73  _enable_turn_on_off_backwards_compatibility = False
74 
75  def __init__(self, touchline_thermostat):
76  """Initialize the Touchline device."""
77  self.unitunit = touchline_thermostat
78  self._name_name = None
79  self._current_temperature_current_temperature = None
80  self._target_temperature_target_temperature = None
81  self._current_operation_mode_current_operation_mode = None
82  self._preset_mode_preset_mode = None
83 
84  def update(self) -> None:
85  """Update thermostat attributes."""
86  self.unitunit.update()
87  self._name_name = self.unitunit.get_name()
88  self._current_temperature_current_temperature = self.unitunit.get_current_temperature()
89  self._target_temperature_target_temperature = self.unitunit.get_target_temperature()
90  self._preset_mode_preset_mode = TOUCHLINE_HA_PRESETS.get(
91  (self.unitunit.get_operation_mode(), self.unitunit.get_week_program())
92  )
93 
94  @property
95  def name(self):
96  """Return the name of the climate device."""
97  return self._name_name
98 
99  @property
101  """Return the current temperature."""
102  return self._current_temperature_current_temperature
103 
104  @property
106  """Return the temperature we try to reach."""
107  return self._target_temperature_target_temperature
108 
109  @property
110  def preset_mode(self):
111  """Return the current preset mode."""
112  return self._preset_mode_preset_mode
113 
114  @property
115  def preset_modes(self):
116  """Return available preset modes."""
117  return list(PRESET_MODES)
118 
119  def set_preset_mode(self, preset_mode):
120  """Set new target preset mode."""
121  preset_mode = PRESET_MODES[preset_mode]
122  self.unitunit.set_operation_mode(preset_mode.mode)
123  self.unitunit.set_week_program(preset_mode.program)
124 
125  def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
126  """Set new target hvac mode."""
127  self._current_operation_mode_current_operation_mode = HVACMode.HEAT
128 
129  def set_temperature(self, **kwargs: Any) -> None:
130  """Set new target temperature."""
131  if kwargs.get(ATTR_TEMPERATURE) is not None:
132  self._target_temperature_target_temperature = kwargs.get(ATTR_TEMPERATURE)
133  self.unitunit.set_target_temperature(self._target_temperature_target_temperature)
None set_hvac_mode(self, HVACMode hvac_mode)
Definition: climate.py:125
def __init__(self, touchline_thermostat)
Definition: climate.py:75
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:52