-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclimate.py
More file actions
executable file
·129 lines (111 loc) · 4.3 KB
/
climate.py
File metadata and controls
executable file
·129 lines (111 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""Climate platform for Systemair SAVE VSR."""
from __future__ import annotations
from homeassistant.components.climate import ClimateEntity, HVACMode, HVACAction, ClimateEntityFeature
from homeassistant.const import UnitOfTemperature, ATTR_TEMPERATURE
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN, SLAVE_ID
from .__init__ import SAVEVSRHub
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities):
hub: SAVEVSRHub = hass.data[DOMAIN][entry.entry_id]
async_add_entities([SAVEVSRClimate(hub)])
class SAVEVSRClimate(CoordinatorEntity[SAVEVSRHub], ClimateEntity):
"""SAVE VSR climate entity."""
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.PRESET_MODE
_attr_hvac_modes = [HVACMode.OFF, HVACMode.AUTO, HVACMode.FAN_ONLY]
_attr_fan_modes = ["low", "medium", "high"]
_attr_preset_modes = ["crowded", "refresh", "fireplace", "away", "holiday", "kitchen", "vacuum_cleaner"]
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_name = "Vent SAVE VSR"
_attr_unique_id = "vsr_vent_SAVE_VSR"
def __init__(self, hub: SAVEVSRHub) -> None:
super().__init__(hub.coordinator)
self.hub = hub
self._attr_device_info = hub.device_info
@property
def current_temperature(self):
return self.coordinator.data.get("temp_supply")
@property
def target_temperature(self):
return self.coordinator.data.get("target_temp")
@property
def hvac_mode(self):
mode = self.coordinator.data.get("mode_main")
if mode == 6:
return HVACMode.OFF
if mode == 0:
return HVACMode.AUTO
if mode == 1:
return HVACMode.FAN_ONLY
return HVACMode.OFF
@property
def hvac_action(self):
# Use Home Assistant's HVACAction enum
if self.hvac_mode == HVACMode.OFF:
return HVACAction.OFF
return HVACAction.FAN
async def async_set_hvac_mode(self, hvac_mode: str):
value: int | None = None
if hvac_mode == HVACMode.OFF:
value = 7
elif hvac_mode == HVACMode.AUTO:
value = 1
elif hvac_mode == HVACMode.FAN_ONLY:
value = 2
if value is None:
return
if await self.hub.async_write_register(1161, value, slave=SLAVE_ID):
await self.coordinator.async_request_refresh()
@property
def fan_mode(self):
speed = self.coordinator.data.get("mode_speed")
if speed == 2:
return "low"
if speed == 3:
return "medium"
if speed == 4:
return "high"
return "low"
async def async_set_fan_mode(self, fan_mode: str):
mapping = {"low": 2, "medium": 3, "high": 4}
value = mapping.get(fan_mode)
if value is None:
return
if await self.hub.async_write_register(1130, value, slave=SLAVE_ID):
await self.coordinator.async_request_refresh()
async def async_set_temperature(self, **kwargs):
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
value = int(temperature * 10) # Scale 0.1 °C
if await self.hub.async_write_register(2000, value, slave=SLAVE_ID):
await self.coordinator.async_request_refresh()
@property
def preset_mode(self):
mode = self.coordinator.data.get("mode_main")
mapping = {
2: "crowded",
3: "refresh",
4: "fireplace",
5: "away",
6: "holiday",
7: "kitchen",
8: "vacuum_cleaner",
}
return mapping.get(mode, None)
async def async_set_preset_mode(self, preset_mode: str):
mapping = {
"crowded": 2,
"refresh": 3,
"fireplace": 4,
"away": 5,
"holiday": 6,
"kitchen": 7,
"vacuum_cleaner": 8,
}
value = mapping.get(preset_mode)
if value is None:
return
if await self.hub.async_write_register(1161, value, slave=SLAVE_ID):
await self.coordinator.async_request_refresh()