1 """Support for deCONZ climate devices."""
3 from __future__
import annotations
7 from pydeconz.models.event
import EventType
8 from pydeconz.models.sensor.thermostat
import (
16 DOMAIN
as CLIMATE_DOMAIN,
36 from .const
import ATTR_LOCKED, ATTR_OFFSET, ATTR_VALVE
37 from .entity
import DeconzDevice
38 from .hub
import DeconzHub
40 DECONZ_FAN_SMART =
"smart"
42 FAN_MODE_TO_DECONZ = {
43 DECONZ_FAN_SMART: ThermostatFanMode.SMART,
44 FAN_AUTO: ThermostatFanMode.AUTO,
45 FAN_HIGH: ThermostatFanMode.HIGH,
46 FAN_MEDIUM: ThermostatFanMode.MEDIUM,
47 FAN_LOW: ThermostatFanMode.LOW,
48 FAN_ON: ThermostatFanMode.ON,
49 FAN_OFF: ThermostatFanMode.OFF,
51 DECONZ_TO_FAN_MODE = {value: key
for key, value
in FAN_MODE_TO_DECONZ.items()}
53 HVAC_MODE_TO_DECONZ = {
54 HVACMode.AUTO: ThermostatMode.AUTO,
55 HVACMode.COOL: ThermostatMode.COOL,
56 HVACMode.HEAT: ThermostatMode.HEAT,
57 HVACMode.OFF: ThermostatMode.OFF,
60 DECONZ_PRESET_AUTO =
"auto"
61 DECONZ_PRESET_COMPLEX =
"complex"
62 DECONZ_PRESET_HOLIDAY =
"holiday"
63 DECONZ_PRESET_MANUAL =
"manual"
65 PRESET_MODE_TO_DECONZ = {
66 DECONZ_PRESET_AUTO: ThermostatPreset.AUTO,
67 PRESET_BOOST: ThermostatPreset.BOOST,
68 PRESET_COMFORT: ThermostatPreset.COMFORT,
69 DECONZ_PRESET_COMPLEX: ThermostatPreset.COMPLEX,
70 PRESET_ECO: ThermostatPreset.ECO,
71 DECONZ_PRESET_HOLIDAY: ThermostatPreset.HOLIDAY,
72 DECONZ_PRESET_MANUAL: ThermostatPreset.MANUAL,
74 DECONZ_TO_PRESET_MODE = {value: key
for key, value
in PRESET_MODE_TO_DECONZ.items()}
79 config_entry: ConfigEntry,
80 async_add_entities: AddEntitiesCallback,
82 """Set up the deCONZ climate devices."""
83 hub = DeconzHub.get_hub(hass, config_entry)
84 hub.entities[CLIMATE_DOMAIN] = set()
87 def async_add_climate(_: EventType, climate_id: str) ->
None:
88 """Add climate from deCONZ."""
89 climate = hub.api.sensors.thermostat[climate_id]
92 hub.register_platform_add_device_callback(
94 hub.api.sensors.thermostat,
99 """Representation of a deCONZ thermostat."""
101 TYPE = CLIMATE_DOMAIN
103 _attr_temperature_unit = UnitOfTemperature.CELSIUS
104 _enable_turn_on_off_backwards_compatibility =
False
106 def __init__(self, device: Thermostat, hub: DeconzHub) ->
None:
107 """Set up thermostat device."""
117 if "coolsetpoint" in device.raw[
"config"]:
121 HVAC_MODE_TO_DECONZ[item]: item
for item
in self.
_attr_hvac_modes_attr_hvac_modes
125 ClimateEntityFeature.TARGET_TEMPERATURE
126 | ClimateEntityFeature.TURN_OFF
127 | ClimateEntityFeature.TURN_ON
142 """Return fan operation."""
143 if self._device.fan_mode
in DECONZ_TO_FAN_MODE:
144 return DECONZ_TO_FAN_MODE[self._device.fan_mode]
145 return FAN_ON
if self._device.state_on
else FAN_OFF
148 """Set new target fan mode."""
149 if fan_mode
not in FAN_MODE_TO_DECONZ:
150 raise ValueError(f
"Unsupported fan mode {fan_mode}")
152 await self.hub.api.sensors.thermostat.set_config(
153 id=self._device.resource_id,
154 fan_mode=FAN_MODE_TO_DECONZ[fan_mode],
161 """Return hvac operation ie. heat, cool mode."""
164 return HVACMode.HEAT
if self._device.state_on
else HVACMode.OFF
167 """Set new target hvac mode."""
169 raise ValueError(f
"Unsupported HVAC mode {hvac_mode}")
172 await self.hub.api.sensors.thermostat.set_config(
173 id=self._device.resource_id,
174 on=hvac_mode != HVACMode.OFF,
177 await self.hub.api.sensors.thermostat.set_config(
178 id=self._device.resource_id,
179 mode=HVAC_MODE_TO_DECONZ[hvac_mode],
184 """Return current hvac operation ie. heat, cool.
186 Preset 'BOOST' is interpreted as 'state_on'.
188 if self._device.mode == ThermostatMode.OFF:
189 return HVACAction.OFF
191 if self._device.state_on
or self._device.preset == ThermostatPreset.BOOST:
192 if self._device.mode == ThermostatMode.COOL:
193 return HVACAction.COOLING
194 return HVACAction.HEATING
195 return HVACAction.IDLE
201 """Return preset mode."""
202 if self._device.preset
in DECONZ_TO_PRESET_MODE:
203 return DECONZ_TO_PRESET_MODE[self._device.preset]
207 """Set new preset mode."""
208 if preset_mode
not in PRESET_MODE_TO_DECONZ:
209 raise ValueError(f
"Unsupported preset mode {preset_mode}")
211 await self.hub.api.sensors.thermostat.set_config(
212 id=self._device.resource_id,
213 preset=PRESET_MODE_TO_DECONZ[preset_mode],
220 """Return the current temperature."""
221 return self._device.scaled_temperature
225 """Return the target temperature."""
226 if self._device.mode == ThermostatMode.COOL
and self._device.cooling_setpoint:
227 return self._device.scaled_cooling_setpoint
229 if self._device.heating_setpoint:
230 return self._device.scaled_heating_setpoint
235 """Set new target temperature."""
236 if ATTR_TEMPERATURE
not in kwargs:
237 raise ValueError(f
"Expected attribute {ATTR_TEMPERATURE}")
239 if self._device.mode == ThermostatMode.COOL:
240 await self.hub.api.sensors.thermostat.set_config(
241 id=self._device.resource_id,
242 cooling_setpoint=kwargs[ATTR_TEMPERATURE] * 100,
245 await self.hub.api.sensors.thermostat.set_config(
246 id=self._device.resource_id,
247 heating_setpoint=kwargs[ATTR_TEMPERATURE] * 100,
252 """Return the state attributes of the thermostat."""
255 if self._device.offset
is not None:
256 attr[ATTR_OFFSET] = self._device.offset
258 if self._device.valve
is not None:
259 attr[ATTR_VALVE] = self._device.valve
261 if self._device.locked
is not None:
262 attr[ATTR_LOCKED] = self._device.locked
None async_set_fan_mode(self, str fan_mode)
None async_set_preset_mode(self, str preset_mode)
None async_set_temperature(self, **Any kwargs)
None __init__(self, Thermostat device, DeconzHub hub)
HVACAction hvac_action(self)
dict[str, bool|int] extra_state_attributes(self)
float current_temperature(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
str|None preset_mode(self)
float|None target_temperature(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)