Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Support for Aqualink Thermostats."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
8 from iaqualink.device import AqualinkThermostat
9 from iaqualink.systems.iaqua.device import AqualinkState
10 
12  DOMAIN as CLIMATE_DOMAIN,
13  ClimateEntity,
14  ClimateEntityFeature,
15  HVACAction,
16  HVACMode,
17 )
18 from homeassistant.config_entries import ConfigEntry
19 from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
20 from homeassistant.core import HomeAssistant
21 from homeassistant.helpers.entity_platform import AddEntitiesCallback
22 
23 from . import refresh_system
24 from .const import DOMAIN as AQUALINK_DOMAIN
25 from .entity import AqualinkEntity
26 from .utils import await_or_reraise
27 
28 _LOGGER = logging.getLogger(__name__)
29 
30 PARALLEL_UPDATES = 0
31 
32 
34  hass: HomeAssistant,
35  config_entry: ConfigEntry,
36  async_add_entities: AddEntitiesCallback,
37 ) -> None:
38  """Set up discovered switches."""
40  (
42  for dev in hass.data[AQUALINK_DOMAIN][CLIMATE_DOMAIN]
43  ),
44  True,
45  )
46 
47 
49  """Representation of a thermostat."""
50 
51  _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF]
52  _attr_supported_features = (
53  ClimateEntityFeature.TARGET_TEMPERATURE
54  | ClimateEntityFeature.TURN_OFF
55  | ClimateEntityFeature.TURN_ON
56  )
57  _enable_turn_on_off_backwards_compatibility = False
58 
59  def __init__(self, dev: AqualinkThermostat) -> None:
60  """Initialize AquaLink thermostat."""
61  super().__init__(dev)
62  self._attr_name_attr_name = dev.label.split(" ")[0]
63  self._attr_temperature_unit_attr_temperature_unit = (
64  UnitOfTemperature.FAHRENHEIT
65  if dev.unit == "F"
66  else UnitOfTemperature.CELSIUS
67  )
68  self._attr_min_temp_attr_min_temp = dev.min_temperature
69  self._attr_max_temp_attr_max_temp = dev.max_temperature
70 
71  @property
72  def hvac_mode(self) -> HVACMode:
73  """Return the current HVAC mode."""
74  if self.devdev.is_on is True:
75  return HVACMode.HEAT
76  return HVACMode.OFF
77 
78  @refresh_system
79  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
80  """Turn the underlying heater switch on or off."""
81  if hvac_mode == HVACMode.HEAT:
82  await await_or_reraise(self.devdev.turn_on())
83  elif hvac_mode == HVACMode.OFF:
84  await await_or_reraise(self.devdev.turn_off())
85  else:
86  _LOGGER.warning("Unknown operation mode: %s", hvac_mode)
87 
88  @property
89  def hvac_action(self) -> HVACAction:
90  """Return the current HVAC action."""
91  state = AqualinkState(self.devdev._heater.state) # noqa: SLF001
92  if state == AqualinkState.ON:
93  return HVACAction.HEATING
94  if state == AqualinkState.ENABLED:
95  return HVACAction.IDLE
96  return HVACAction.OFF
97 
98  @property
99  def target_temperature(self) -> float:
100  """Return the current target temperature."""
101  return float(self.devdev.state)
102 
103  @refresh_system
104  async def async_set_temperature(self, **kwargs: Any) -> None:
105  """Set new target temperature."""
106  await await_or_reraise(self.devdev.set_temperature(int(kwargs[ATTR_TEMPERATURE])))
107 
108  @property
109  def current_temperature(self) -> float | None:
110  """Return the current temperature."""
111  if self.devdev.current_temperature != "":
112  return float(self.devdev.current_temperature)
113  return None
None set_temperature(self, **Any kwargs)
Definition: __init__.py:771