forked from mduran80/daikin_madoka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclimate.py
354 lines (293 loc) · 11.2 KB
/
climate.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
"""Support for the Daikin HVAC."""
import logging
from pymadoka.connection import ConnectionStatus
import voluptuous as vol
from pymadoka import (
Controller,
PowerState,
PowerStateStatus,
FanSpeed,
FanSpeedEnum,
FanSpeedStatus,
OperationMode,
OperationModeEnum,
OperationModeStatus,
SetPoint,
SetPointStatus,
Temperatures,
TemperaturesStatus,
ConnectionException
)
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
from homeassistant.components.climate.const import (
ATTR_FAN_MODE,
ATTR_HVAC_MODE,
CURRENT_HVAC_ACTIONS,
FAN_OFF,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
CURRENT_HVAC_COOL,
CURRENT_HVAC_DRY,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_FAN,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
FAN_AUTO,
FAN_LOW,
FAN_MEDIUM,
FAN_HIGH,
)
from homeassistant.const import (
ATTR_TEMPERATURE,
CONF_DEVICES,
CONF_DEVICE,
CONF_SCAN_INTERVAL,
CONF_NAME,
CONF_FORCE_UPDATE,
TEMP_CELSIUS,
)
import homeassistant.helpers.config_validation as cv
from . import DOMAIN
from .const import CONTROLLERS, MAX_TEMP, MIN_TEMP
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_DEVICE): cv.string
}
)
_LOGGER = logging.getLogger(__name__)
# PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
# {vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME): cv.string}
# )
HA_MODE_TO_DAIKIN = {
HVAC_MODE_FAN_ONLY: OperationModeEnum.FAN,
HVAC_MODE_DRY: OperationModeEnum.DRY,
HVAC_MODE_COOL: OperationModeEnum.COOL,
HVAC_MODE_HEAT: OperationModeEnum.HEAT,
HVAC_MODE_AUTO: OperationModeEnum.AUTO,
HVAC_MODE_OFF: OperationModeEnum.AUTO,
}
DAIKIN_TO_HA_MODE = {
OperationModeEnum.FAN: HVAC_MODE_FAN_ONLY,
OperationModeEnum.DRY: HVAC_MODE_DRY,
OperationModeEnum.COOL: HVAC_MODE_COOL,
OperationModeEnum.HEAT: HVAC_MODE_HEAT,
OperationModeEnum.AUTO: HVAC_MODE_AUTO,
}
HA_FAN_MODE_TO_DAIKIN = {
FAN_LOW: FanSpeedEnum.LOW,
FAN_MEDIUM: FanSpeedEnum.MID,
FAN_HIGH: FanSpeedEnum.HIGH,
FAN_AUTO: FanSpeedEnum.AUTO
}
DAIKIN_TO_HA_FAN_MODE = {
FanSpeedEnum.LOW: FAN_LOW,
FanSpeedEnum.MID: FAN_MEDIUM,
FanSpeedEnum.HIGH: FAN_HIGH,
FanSpeedEnum.AUTO: FAN_AUTO,
}
DAIKIN_TO_HA_CURRENT_HVAC_MODE = {
OperationModeEnum.FAN: CURRENT_HVAC_FAN,
OperationModeEnum.DRY: CURRENT_HVAC_DRY,
OperationModeEnum.COOL: CURRENT_HVAC_COOL,
OperationModeEnum.HEAT: CURRENT_HVAC_HEAT
}
DATA = "data"
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Old way of setting up the Daikin HVAC platform.
Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Daikin climate based on config_entry."""
entities = []
config = entry.data
for controller in hass.data[DOMAIN][CONTROLLERS].values():
try:
entity = DaikinMadokaClimate(controller)
entities.append(entity)
await entity.controller.update()
except ConnectionAbortedError:
pass
async_add_entities(entities, update_before_add=True)
class DaikinMadokaClimate(ClimateEntity):
"""Representation of a Daikin HVAC."""
def __init__(self, controller:Controller):
"""Initialize the climate device."""
self.controller = controller
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
@property
def available(self):
"""Return the availability."""
return self.controller.connection.connection_status == ConnectionStatus.CONNECTED
@property
def name(self):
"""Return the name of the thermostat, if any."""
return self.controller.connection.name if self.controller.connection.name is not None else self.controller.connection.address
@property
def unique_id(self):
"""Return a unique ID."""
return self.controller.connection.address
@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
@property
def current_temperature(self):
"""Return the current temperature."""
if self.controller.temperatures.status is None:
return None
return self.controller.temperatures.status.indoor
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if self.controller.set_point.status is None:
return MIN_TEMP
if self.hvac_mode == HVAC_MODE_HEAT:
return self.controller.set_point.status.heating_set_point
else:
return self.controller.set_point.status.cooling_set_point
@property
def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 1
@property
def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMP
@property
def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMP
async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
try:
_LOGGER.debug(f"Setting temperature of device {self.name}")
new_cooling_set_point = self.controller.set_point.status.cooling_set_point
new_heating_set_point = self.controller.set_point.status.cooling_set_point
if (self.controller.operation_mode.status.operation_mode != OperationModeEnum.HEAT):
new_cooling_set_point = round(kwargs.get(ATTR_TEMPERATURE))
if self.controller.operation_mode.status.operation_mode != OperationModeEnum.COOL:
new_heating_set_point = round(kwargs.get(ATTR_TEMPERATURE))
await self.controller.set_point.update(
SetPointStatus(new_cooling_set_point,new_heating_set_point)
)
except ConnectionAbortedError:
_LOGGER.info(f"Could not set target temperature on {self.name}. Connection not available, please reload integration to try reenabling.")
except ConnectionException:
pass
@property
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle."""
if self.controller.power_state.status.turn_on == False:
return HVAC_MODE_OFF
_LOGGER.debug(f"Getting operation mode of device {self.name}")
return DAIKIN_TO_HA_MODE.get(
self.controller.operation_mode.status.operation_mode
)
@property
def hvac_modes(self):
"""Return the list of available operation modes."""
return list(HA_MODE_TO_DAIKIN)
@property
def hvac_action(self):
"""Return the HVAC current action."""
if self.controller.power_state.status.turn_on == False :
return CURRENT_HVAC_OFF
if self.controller.operation_mode.status.operation_mode == OperationModeEnum.AUTO:
if self.target_temperature == self.current_temperature:
return CURRENT_HVAC_IDLE
elif self.target_temperature > self.current_temperature:
return CURRENT_HVAC_HEAT
else:
return CURRENT_HVAC_COOL
else:
_LOGGER.debug(f"Getting operation mode of device {self.name}")
return DAIKIN_TO_HA_MODE.get(self.controller.operation_mode.status.operation_mode)
async def async_set_hvac_mode(self, hvac_mode):
"""Set HVAC mode."""
try:
_LOGGER.debug(f"Setting operation mode of device {self.name}")
await self.controller.operation_mode.update(
OperationModeStatus(HA_MODE_TO_DAIKIN.get(hvac_mode))
)
await self.controller.power_state.update(
PowerStateStatus(hvac_mode != HVAC_MODE_OFF))
self.async_schedule_update_ha_state()
except ConnectionAbortedError:
_LOGGER.info(f"Could not set HVAC mode on {self.name}. Connection not available, please reload integration to try reenabling.")
except ConnectionException:
pass
@property
def fan_mode(self):
"""Return the fan setting."""
if self.controller.fan_speed.status is None:
return FAN_OFF
if self.hvac_mode == HVAC_MODE_HEAT:
_LOGGER.debug(f"Getting heating fan speed of device {self.name}")
return DAIKIN_TO_HA_FAN_MODE.get(
self.controller.fan_speed.status.heating_fan_speed
)
else:
_LOGGER.debug(f"Getting cooling fan speed of device {self.name}")
return DAIKIN_TO_HA_FAN_MODE.get(
self.controller.fan_speed.status.cooling_fan_speed
)
async def async_set_fan_mode(self, fan_mode):
"""Set fan mode."""
try:
_LOGGER.debug(f"Setting fan speed of device {self.name}")
await self.controller.fan_speed.update(
FanSpeedStatus(
HA_FAN_MODE_TO_DAIKIN.get(fan_mode), HA_FAN_MODE_TO_DAIKIN.get(fan_mode)
)
)
except ConnectionAbortedError:
_LOGGER.info(f"Could not set fan mode on {self.name}. Connection not available, please reload integration to try reenabling.")
except ConnectionException:
pass
@property
def fan_modes(self):
"""List of available fan modes."""
return list(HA_FAN_MODE_TO_DAIKIN)
async def async_update(self):
"""Retrieve latest state."""
try:
_LOGGER.debug(f"Updating device status for {self.name}")
await self.controller.read_info()
await self.controller.update()
except ConnectionAbortedError:
_LOGGER.info(f"Could not update device status for {self.name}. Connection not available, please reload integration to try reenabling.")
except ConnectionException:
pass
async def async_turn_on(self):
"""Turn device on."""
try:
_LOGGER.debug(f"Turning ON device {self.name}")
await self.controller.power_state.update(PowerStateStatus(True))
except ConnectionAbortedError:
_LOGGER.info(f"Could not turn on {self.name}. Connection not available, please reload integration to try reenabling.")
except ConnectionException:
pass
async def async_turn_off(self):
"""Turn device off."""
try:
_LOGGER.debug(f"Turning OFF device {self.name}")
await self.controller.power_state.update(PowerStateStatus(False))
except ConnectionAbortedError:
_LOGGER.info(f"Could not turn off {self.name}. Connection not available, please reload integration to try reenabling.")
except ConnectionException:
pass
@property
async def async_device_info(self):
"""Return a device description for device registry."""
return await self.controller.read_info()