Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Support for XS1 climate devices."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from xs1_api_client.api_constants import ActuatorType
8 
10  ClimateEntity,
11  ClimateEntityFeature,
12  HVACMode,
13 )
14 from homeassistant.const import ATTR_TEMPERATURE
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 ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS
20 from .entity import XS1DeviceEntity
21 
22 MIN_TEMP = 8
23 MAX_TEMP = 25
24 
25 
27  hass: HomeAssistant,
28  config: ConfigType,
29  add_entities: AddEntitiesCallback,
30  discovery_info: DiscoveryInfoType | None = None,
31 ) -> None:
32  """Set up the XS1 thermostat platform."""
33  actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
34  sensors = hass.data[COMPONENT_DOMAIN][SENSORS]
35 
36  thermostat_entities = []
37  for actuator in actuators:
38  if actuator.type() == ActuatorType.TEMPERATURE:
39  # Search for a matching sensor (by name)
40  actuator_name = actuator.name()
41 
42  matching_sensor = None
43  for sensor in sensors:
44  if actuator_name in sensor.name():
45  matching_sensor = sensor
46  break
47 
48  thermostat_entities.append(XS1ThermostatEntity(actuator, matching_sensor))
49 
50  add_entities(thermostat_entities)
51 
52 
54  """Representation of a XS1 thermostat."""
55 
56  _attr_hvac_mode = HVACMode.HEAT
57  _attr_hvac_modes = [HVACMode.HEAT]
58  _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
59  _enable_turn_on_off_backwards_compatibility = False
60 
61  def __init__(self, device, sensor):
62  """Initialize the actuator."""
63  super().__init__(device)
64  self.sensorsensor = sensor
65 
66  @property
67  def name(self):
68  """Return the name of the device if any."""
69  return self.devicedevice.name()
70 
71  @property
73  """Return the current temperature."""
74  if self.sensorsensor is None:
75  return None
76 
77  return self.sensorsensor.value()
78 
79  @property
80  def temperature_unit(self) -> str:
81  """Return the unit of measurement used by the platform."""
82  return self.devicedevice.unit()
83 
84  @property
85  def target_temperature(self):
86  """Return the current target temperature."""
87  return self.devicedevice.new_value()
88 
89  @property
90  def min_temp(self):
91  """Return the minimum temperature."""
92  return MIN_TEMP
93 
94  @property
95  def max_temp(self):
96  """Return the maximum temperature."""
97  return MAX_TEMP
98 
99  def set_temperature(self, **kwargs: Any) -> None:
100  """Set new target temperature."""
101  temp = kwargs.get(ATTR_TEMPERATURE)
102 
103  self.devicedevice.set_value(temp)
104 
105  if self.sensorsensor is not None:
106  self.schedule_update_ha_stateschedule_update_ha_state()
107 
108  def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
109  """Set new target hvac mode."""
110 
111  async def async_update(self) -> None:
112  """Also update the sensor when available."""
113  await super().async_update()
114  if self.sensorsensor is not None:
115  await self.hasshass.async_add_executor_job(self.sensorsensor.update)
None set_hvac_mode(self, HVACMode hvac_mode)
Definition: climate.py:108
None schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1244
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:31