Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Support for LightwaveRF TRVs."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
8  DEFAULT_MAX_TEMP,
9  DEFAULT_MIN_TEMP,
10  ClimateEntity,
11  ClimateEntityFeature,
12  HVACAction,
13  HVACMode,
14 )
15 from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, UnitOfTemperature
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
19 
20 from . import CONF_SERIAL, LIGHTWAVE_LINK
21 
22 
24  hass: HomeAssistant,
25  config: ConfigType,
26  async_add_entities: AddEntitiesCallback,
27  discovery_info: DiscoveryInfoType | None = None,
28 ) -> None:
29  """Find and return LightWave lights."""
30  if discovery_info is None:
31  return
32 
33  entities = []
34  lwlink = hass.data[LIGHTWAVE_LINK]
35 
36  for device_id, device_config in discovery_info.items():
37  name = device_config[CONF_NAME]
38  serial = device_config[CONF_SERIAL]
39  entities.append(LightwaveTrv(name, device_id, lwlink, serial))
40 
41  async_add_entities(entities)
42 
43 
45  """Representation of a LightWaveRF TRV."""
46 
47  _attr_hvac_mode = HVACMode.HEAT
48  _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF]
49  _attr_min_temp = DEFAULT_MIN_TEMP
50  _attr_max_temp = DEFAULT_MAX_TEMP
51  _attr_supported_features = (
52  ClimateEntityFeature.TARGET_TEMPERATURE
53  | ClimateEntityFeature.TURN_OFF
54  | ClimateEntityFeature.TURN_ON
55  )
56  _attr_target_temperature_step = 0.5
57  _attr_temperature_unit = UnitOfTemperature.CELSIUS
58  _enable_turn_on_off_backwards_compatibility = False
59 
60  def __init__(self, name, device_id, lwlink, serial):
61  """Initialize LightwaveTrv entity."""
62  self._attr_name_attr_name = name
63  self._device_id_device_id = device_id
64  self._lwlink_lwlink = lwlink
65  self._serial_serial = serial
66  self._attr_unique_id_attr_unique_id = f"{serial}-trv"
67  # inhibit is used to prevent race condition on update. If non zero, skip next update cycle.
68  self._inhibit_inhibit = 0
69 
70  def update(self) -> None:
71  """Communicate with a Lightwave RTF Proxy to get state."""
72  (temp, targ, _, trv_output) = self._lwlink_lwlink.read_trv_status(self._serial_serial)
73  if temp is not None:
74  self._attr_current_temperature_attr_current_temperature = temp
75  if targ is not None:
76  if self._inhibit_inhibit == 0:
77  self._attr_target_temperature_attr_target_temperature = targ
78  if targ == 0:
79  # TRV off
80  self._attr_target_temperature_attr_target_temperature = None
81  if targ >= 40:
82  # Call for heat mode, or TRV in a fixed position
83  self._attr_target_temperature_attr_target_temperature = None
84  else:
85  # Done the job - use proxy next iteration
86  self._inhibit_inhibit = 0
87  if trv_output is not None:
88  if trv_output > 0:
89  self._attr_hvac_action_attr_hvac_action = HVACAction.HEATING
90  else:
91  self._attr_hvac_action_attr_hvac_action = HVACAction.OFF
92 
93  @property
94  def target_temperature(self):
95  """Target room temperature."""
96  if self._inhibit_inhibit > 0:
97  # If we get an update before the new temp has
98  # propagated, the target temp is set back to the
99  # old target on the next poll, showing a false
100  # reading temporarily.
101  self._attr_target_temperature_attr_target_temperature = self._inhibit_inhibit
102  return self._attr_target_temperature_attr_target_temperature
103 
104  def set_temperature(self, **kwargs: Any) -> None:
105  """Set TRV target temperature."""
106  if ATTR_TEMPERATURE in kwargs:
107  self._attr_target_temperature_attr_target_temperature = kwargs[ATTR_TEMPERATURE]
108  self._inhibit_inhibit = self._attr_target_temperature_attr_target_temperature
109  self._lwlink_lwlink.set_temperature(
110  self._device_id_device_id, self._attr_target_temperature_attr_target_temperature, self._attr_name_attr_name
111  )
112 
113  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
114  """Set HVAC Mode for TRV."""
def __init__(self, name, device_id, lwlink, serial)
Definition: climate.py:60
None async_set_hvac_mode(self, HVACMode hvac_mode)
Definition: climate.py:113
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: climate.py:28