Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """nVent RAYCHEM SENZ climate platform."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from aiosenz import MODE_AUTO, Thermostat
8 
10  ClimateEntity,
11  ClimateEntityFeature,
12  HVACAction,
13  HVACMode,
14 )
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
17 from homeassistant.core import HomeAssistant, callback
18 from homeassistant.helpers.device_registry import DeviceInfo
19 from homeassistant.helpers.entity_platform import AddEntitiesCallback
20 from homeassistant.helpers.update_coordinator import CoordinatorEntity
21 
22 from . import SENZDataUpdateCoordinator
23 from .const import DOMAIN
24 
25 
27  hass: HomeAssistant,
28  entry: ConfigEntry,
29  async_add_entities: AddEntitiesCallback,
30 ) -> None:
31  """Set up the SENZ climate entities from a config entry."""
32  coordinator: SENZDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
34  SENZClimate(thermostat, coordinator) for thermostat in coordinator.data.values()
35  )
36 
37 
39  """Representation of a SENZ climate entity."""
40 
41  _attr_temperature_unit = UnitOfTemperature.CELSIUS
42  _attr_precision = PRECISION_TENTHS
43  _attr_hvac_modes = [HVACMode.HEAT, HVACMode.AUTO]
44  _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
45  _attr_max_temp = 35
46  _attr_min_temp = 5
47  _attr_has_entity_name = True
48  _attr_name = None
49  _enable_turn_on_off_backwards_compatibility = False
50 
51  def __init__(
52  self,
53  thermostat: Thermostat,
54  coordinator: SENZDataUpdateCoordinator,
55  ) -> None:
56  """Init SENZ climate."""
57  super().__init__(coordinator)
58  self._thermostat_thermostat = thermostat
59  self._attr_unique_id_attr_unique_id = thermostat.serial_number
60  self._attr_device_info_attr_device_info = DeviceInfo(
61  identifiers={(DOMAIN, thermostat.serial_number)},
62  manufacturer="nVent Raychem",
63  model="SENZ WIFI",
64  name=thermostat.name,
65  )
66 
67  @callback
68  def _handle_coordinator_update(self) -> None:
69  """Handle updated data from the coordinator."""
70  self._thermostat_thermostat = self.coordinator.data[self._thermostat_thermostat.serial_number]
71  self.async_write_ha_stateasync_write_ha_state()
72 
73  @property
74  def current_temperature(self) -> float:
75  """Return the current temperature."""
76  return self._thermostat_thermostat.current_temperatue
77 
78  @property
79  def target_temperature(self) -> float:
80  """Return the temperature we try to reach."""
81  return self._thermostat_thermostat.setpoint_temperature
82 
83  @property
84  def available(self) -> bool:
85  """Return True if the thermostat is available."""
86  return self._thermostat_thermostat.online
87 
88  @property
89  def hvac_mode(self) -> HVACMode:
90  """Return hvac operation ie. auto, heat mode."""
91  if self._thermostat_thermostat.mode == MODE_AUTO:
92  return HVACMode.AUTO
93  return HVACMode.HEAT
94 
95  @property
96  def hvac_action(self) -> HVACAction:
97  """Return current hvac action."""
98  return HVACAction.HEATING if self._thermostat_thermostat.is_heating else HVACAction.IDLE
99 
100  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
101  """Set new target hvac mode."""
102  if hvac_mode == HVACMode.AUTO:
103  await self._thermostat_thermostat.auto()
104  else:
105  await self._thermostat_thermostat.manual()
106  await self.coordinator.async_request_refresh()
107 
108  async def async_set_temperature(self, **kwargs: Any) -> None:
109  """Set new target temperature."""
110  temp: float = kwargs[ATTR_TEMPERATURE]
111  await self._thermostat_thermostat.manual(temp)
112  await self.coordinator.async_request_refresh()
None async_set_hvac_mode(self, HVACMode hvac_mode)
Definition: climate.py:100
None async_set_temperature(self, **Any kwargs)
Definition: climate.py:108
None __init__(self, Thermostat thermostat, SENZDataUpdateCoordinator coordinator)
Definition: climate.py:55
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: climate.py:30