Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Representation of a thermostat."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from zwave_me_ws import ZWaveMeData
8 
10  ClimateEntity,
11  ClimateEntityFeature,
12  HVACMode,
13 )
14 from homeassistant.config_entries import ConfigEntry
15 from homeassistant.const import ATTR_TEMPERATURE
16 from homeassistant.core import HomeAssistant, callback
17 from homeassistant.helpers.dispatcher import async_dispatcher_connect
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 
20 from .const import DOMAIN, ZWaveMePlatform
21 from .entity import ZWaveMeEntity
22 
23 TEMPERATURE_DEFAULT_STEP = 0.5
24 
25 DEVICE_NAME = ZWaveMePlatform.CLIMATE
26 
27 
29  hass: HomeAssistant,
30  config_entry: ConfigEntry,
31  async_add_entities: AddEntitiesCallback,
32 ) -> None:
33  """Set up the climate platform."""
34 
35  @callback
36  def add_new_device(new_device: ZWaveMeData) -> None:
37  """Add a new device."""
38  controller = hass.data[DOMAIN][config_entry.entry_id]
39  climate = ZWaveMeClimate(controller, new_device)
40 
42  [
43  climate,
44  ]
45  )
46 
47  config_entry.async_on_unload(
49  hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
50  )
51  )
52 
53 
55  """Representation of a ZWaveMe sensor."""
56 
57  _attr_hvac_mode = HVACMode.HEAT
58  _attr_hvac_modes = [HVACMode.HEAT]
59  _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
60  _enable_turn_on_off_backwards_compatibility = False
61 
62  def set_temperature(self, **kwargs: Any) -> None:
63  """Set new target temperature."""
64  if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
65  return
66 
67  self.controllercontroller.zwave_api.send_command(
68  self.devicedevice.id, f"exact?level={temperature}"
69  )
70 
71  @property
72  def temperature_unit(self) -> str:
73  """Return the temperature_unit."""
74  return self.devicedevice.scaleTitle
75 
76  @property
77  def target_temperature(self) -> float:
78  """Return the state of the sensor."""
79  return self.devicedevice.level
80 
81  @property
82  def max_temp(self) -> float:
83  """Return min temperature for the device."""
84  return self.devicedevice.max
85 
86  @property
87  def min_temp(self) -> float:
88  """Return max temperature for the device."""
89  return self.devicedevice.min
90 
91  @property
92  def target_temperature_step(self) -> float:
93  """Return the supported step of target temperature."""
94  return TEMPERATURE_DEFAULT_STEP
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: climate.py:32
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103