1 """Platform for climate integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from pymelcloud
import DEVICE_TYPE_ATA, DEVICE_TYPE_ATW, AtaDevice, AtwDevice
9 import pymelcloud.ata_device
as ata
10 import pymelcloud.atw_device
as atw
11 from pymelcloud.atw_device
import (
12 PROPERTY_ZONE_1_OPERATION_MODE,
13 PROPERTY_ZONE_2_OPERATION_MODE,
16 import voluptuous
as vol
33 from .
import MelCloudDevice
37 ATTR_VANE_HORIZONTAL_POSITIONS,
39 ATTR_VANE_VERTICAL_POSITIONS,
42 SERVICE_SET_VANE_HORIZONTAL,
43 SERVICE_SET_VANE_VERTICAL,
49 ATA_HVAC_MODE_LOOKUP = {
50 ata.OPERATION_MODE_HEAT: HVACMode.HEAT,
51 ata.OPERATION_MODE_DRY: HVACMode.DRY,
52 ata.OPERATION_MODE_COOL: HVACMode.COOL,
53 ata.OPERATION_MODE_FAN_ONLY: HVACMode.FAN_ONLY,
54 ata.OPERATION_MODE_HEAT_COOL: HVACMode.HEAT_COOL,
56 ATA_HVAC_MODE_REVERSE_LOOKUP = {v: k
for k, v
in ATA_HVAC_MODE_LOOKUP.items()}
59 ATW_ZONE_HVAC_MODE_LOOKUP = {
60 atw.ZONE_OPERATION_MODE_HEAT: HVACMode.HEAT,
61 atw.ZONE_OPERATION_MODE_COOL: HVACMode.COOL,
63 ATW_ZONE_HVAC_MODE_REVERSE_LOOKUP = {v: k
for k, v
in ATW_ZONE_HVAC_MODE_LOOKUP.items()}
65 ATW_ZONE_HVAC_ACTION_LOOKUP = {
66 atw.STATUS_IDLE: HVACAction.IDLE,
67 atw.STATUS_HEAT_ZONES: HVACAction.HEATING,
68 atw.STATUS_COOL: HVACAction.COOLING,
69 atw.STATUS_STANDBY: HVACAction.IDLE,
71 atw.STATUS_HEAT_WATER: HVACAction.IDLE,
72 atw.STATUS_LEGIONELLA: HVACAction.IDLE,
74 atw.STATUS_DEFROST: HVACAction.PREHEATING,
79 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
81 """Set up MelCloud device climate based on config_entry."""
82 mel_devices = hass.data[DOMAIN][entry.entry_id]
83 entities: list[AtaDeviceClimate | AtwDeviceZoneClimate] = [
85 for mel_device
in mel_devices[DEVICE_TYPE_ATA]
90 for mel_device
in mel_devices[DEVICE_TYPE_ATW]
91 for zone
in mel_device.device.zones
99 platform = entity_platform.async_get_current_platform()
100 platform.async_register_entity_service(
101 SERVICE_SET_VANE_HORIZONTAL,
102 {vol.Required(CONF_POSITION): cv.string},
103 "async_set_vane_horizontal",
105 platform.async_register_entity_service(
106 SERVICE_SET_VANE_VERTICAL,
107 {vol.Required(CONF_POSITION): cv.string},
108 "async_set_vane_vertical",
113 """Base climate device."""
115 _attr_temperature_unit = UnitOfTemperature.CELSIUS
116 _attr_has_entity_name =
True
118 _enable_turn_on_off_backwards_compatibility =
False
120 def __init__(self, device: MelCloudDevice) ->
None:
121 """Initialize the climate."""
126 """Update state from MELCloud."""
131 """Return the supported step of target temperature."""
132 return self.
_base_device_base_device.temperature_increment
136 """Air-to-Air climate device."""
138 _attr_supported_features = (
139 ClimateEntityFeature.FAN_MODE
140 | ClimateEntityFeature.TARGET_TEMPERATURE
141 | ClimateEntityFeature.SWING_MODE
142 | ClimateEntityFeature.TURN_OFF
143 | ClimateEntityFeature.TURN_ON
146 def __init__(self, device: MelCloudDevice, ata_device: AtaDevice) ->
None:
147 """Initialize the climate."""
151 self.
_attr_unique_id_attr_unique_id = f
"{self.api.device.serial}-{self.api.device.mac}"
156 """Return the optional state attributes with device specific additions."""
159 if vane_horizontal := self.
_device_device.vane_horizontal:
162 ATTR_VANE_HORIZONTAL: vane_horizontal,
163 ATTR_VANE_HORIZONTAL_POSITIONS: self.
_device_device.vane_horizontal_positions,
167 if vane_vertical := self.
_device_device.vane_vertical:
170 ATTR_VANE_VERTICAL: vane_vertical,
171 ATTR_VANE_VERTICAL_POSITIONS: self.
_device_device.vane_vertical_positions,
178 """Return hvac operation ie. heat, cool mode."""
179 mode = self.
_device_device.operation_mode
180 if not self.
_device_device.power
or mode
is None:
182 return ATA_HVAC_MODE_LOOKUP.get(mode)
185 self, hvac_mode: HVACMode, set_dict: dict[str, Any]
187 """Apply hvac mode changes to a dict used to call _device.set."""
188 if hvac_mode == HVACMode.OFF:
189 set_dict[
"power"] =
False
192 operation_mode = ATA_HVAC_MODE_REVERSE_LOOKUP.get(hvac_mode)
193 if operation_mode
is None:
194 raise ValueError(f
"Invalid hvac_mode [{hvac_mode}]")
196 set_dict[
"operation_mode"] = operation_mode
198 set_dict[
"power"] =
True
201 """Set new target hvac mode."""
202 set_dict: dict[str, Any] = {}
204 await self.
_device_device.set(set_dict)
208 """Return the list of available hvac operation modes."""
209 return [HVACMode.OFF] + [
210 ATA_HVAC_MODE_LOOKUP[mode]
211 for mode
in self.
_device_device.operation_modes
212 if mode
in ATA_HVAC_MODE_LOOKUP
217 """Return the current temperature."""
218 return self.
_device_device.room_temperature
222 """Return the temperature we try to reach."""
223 return self.
_device_device.target_temperature
226 """Set new target temperature."""
227 set_dict: dict[str, Any] = {}
228 if ATTR_HVAC_MODE
in kwargs:
233 if ATTR_TEMPERATURE
in kwargs:
234 set_dict[
"target_temperature"] = kwargs.get(ATTR_TEMPERATURE)
237 await self.
_device_device.set(set_dict)
241 """Return the fan setting."""
242 return self.
_device_device.fan_speed
245 """Set new target fan mode."""
246 await self.
_device_device.set({
"fan_speed": fan_mode})
250 """Return the list of available fan modes."""
251 return self.
_device_device.fan_speeds
254 """Set horizontal vane position."""
255 if position
not in self.
_device_device.vane_horizontal_positions:
257 f
"Invalid horizontal vane position {position}. Valid positions:"
258 f
" [{self._device.vane_horizontal_positions}]."
260 await self.
_device_device.set({ata.PROPERTY_VANE_HORIZONTAL: position})
263 """Set vertical vane position."""
264 if position
not in self.
_device_device.vane_vertical_positions:
266 f
"Invalid vertical vane position {position}. Valid positions:"
267 f
" [{self._device.vane_vertical_positions}]."
269 await self.
_device_device.set({ata.PROPERTY_VANE_VERTICAL: position})
273 """Return vertical vane position or mode."""
274 return self.
_device_device.vane_vertical
277 """Set vertical vane position or mode."""
282 """Return a list of available vertical vane positions and modes."""
283 return self.
_device_device.vane_vertical_positions
286 """Turn the entity on."""
287 await self.
_device_device.set({
"power":
True})
290 """Turn the entity off."""
291 await self.
_device_device.set({
"power":
False})
295 """Return the minimum temperature."""
296 min_value = self.
_device_device.target_temperature_min
297 if min_value
is not None:
300 return DEFAULT_MIN_TEMP
304 """Return the maximum temperature."""
305 max_value = self.
_device_device.target_temperature_max
306 if max_value
is not None:
309 return DEFAULT_MAX_TEMP
313 """Air-to-Water zone climate device."""
317 _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
320 self, device: MelCloudDevice, atw_device: AtwDevice, atw_zone: Zone
322 """Initialize the climate."""
327 self.
_attr_unique_id_attr_unique_id = f
"{self.api.device.serial}-{atw_zone.zone_index}"
332 """Return the optional state attributes with device specific additions."""
334 ATTR_STATUS: ATW_ZONE_HVAC_MODE_LOOKUP.get(
335 self.
_zone_zone.status, self.
_zone_zone.status
341 """Return hvac operation ie. heat, cool mode."""
342 mode = self.
_zone_zone.operation_mode
343 if not self.
_device_device.power
or mode
is None:
345 return ATW_ZONE_HVAC_MODE_LOOKUP.get(mode, HVACMode.OFF)
348 """Set new target hvac mode."""
349 if hvac_mode == HVACMode.OFF:
350 await self.
_device_device.set({
"power":
False})
353 operation_mode = ATW_ZONE_HVAC_MODE_REVERSE_LOOKUP.get(hvac_mode)
354 if operation_mode
is None:
355 raise ValueError(f
"Invalid hvac_mode [{hvac_mode}]")
357 if self.
_zone_zone.zone_index == 1:
358 props = {PROPERTY_ZONE_1_OPERATION_MODE: operation_mode}
360 props = {PROPERTY_ZONE_2_OPERATION_MODE: operation_mode}
362 props[
"power"] =
True
363 await self.
_device_device.set(props)
367 """Return the list of available hvac operation modes."""
372 """Return the current running hvac operation."""
373 if not self.
_device_device.power:
374 return HVACAction.OFF
375 return ATW_ZONE_HVAC_ACTION_LOOKUP.get(self.
_device_device.status)
379 """Return the current temperature."""
380 return self.
_zone_zone.room_temperature
384 """Return the temperature we try to reach."""
385 return self.
_zone_zone.target_temperature
388 """Set new target temperature."""
389 await self.
_zone_zone.set_target_temperature(
float|None target_temperature(self)
HVACMode|None hvac_mode(self)
dict[str, Any]|None extra_state_attributes(self)
None async_set_vane_vertical(self, str position)
None async_turn_off(self)
None async_set_vane_horizontal(self, str position)
list[HVACMode] hvac_modes(self)
HVACMode|None hvac_mode(self)
None __init__(self, MelCloudDevice device, AtaDevice ata_device)
str|None swing_mode(self)
list[str]|None fan_modes(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_swing_mode(self, str swing_mode)
None async_set_temperature(self, **Any kwargs)
None _apply_set_hvac_mode(self, HVACMode hvac_mode, dict[str, Any] set_dict)
float|None current_temperature(self)
float|None target_temperature(self)
list[str]|None swing_modes(self)
None async_set_fan_mode(self, str fan_mode)
HVACAction|None hvac_action(self)
None __init__(self, MelCloudDevice device, AtwDevice atw_device, Zone atw_zone)
dict[str, Any] extra_state_attributes(self)
float|None target_temperature(self)
None async_set_temperature(self, **Any kwargs)
list[HVACMode] hvac_modes(self)
float|None current_temperature(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None __init__(self, MelCloudDevice device)
float|None target_temperature_step(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)