1
1
"""Support for the Daikin HVAC."""
2
-
3
2
import logging
4
3
import re
5
4
9
8
from homeassistant .components .climate import PLATFORM_SCHEMA
10
9
from homeassistant .components .climate .const import ATTR_HVAC_MODE
11
10
from homeassistant .components .climate .const import ClimateEntityFeature
12
- from homeassistant .components .climate .const import FAN_AUTO
13
11
from homeassistant .components .climate .const import HVACMode
14
12
from homeassistant .components .climate .const import PRESET_AWAY
15
13
from homeassistant .components .climate .const import PRESET_BOOST
@@ -74,9 +72,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
74
72
device_model = device .daikin_data ["deviceModel" ]
75
73
supported_management_point_types = {"climateControl" }
76
74
managementPoints = device .daikin_data .get ("managementPoints" , [])
75
+ embedded_id = ""
77
76
for management_point in managementPoints :
78
77
management_point_type = management_point ["managementPointType" ]
79
78
if management_point_type in supported_management_point_types :
79
+ embedded_id = management_point .get ("embeddedId" )
80
80
# Check if we have a temperatureControl
81
81
temperatureControl = management_point .get ("temperatureControl" )
82
82
if temperatureControl is not None :
@@ -88,7 +88,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
88
88
modes = list (dict .fromkeys (modes ))
89
89
_LOGGER .info ("Climate: Device '%s' has modes %s" , device_model , modes )
90
90
for mode in modes :
91
- async_add_entities ([DaikinClimate (device , mode , coordinator )], update_before_add = False )
91
+ async_add_entities (
92
+ [DaikinClimate (device , mode , coordinator , embedded_id )],
93
+ update_before_add = False ,
94
+ )
92
95
93
96
94
97
class DaikinClimate (CoordinatorEntity , ClimateEntity ):
@@ -98,7 +101,7 @@ class DaikinClimate(CoordinatorEntity, ClimateEntity):
98
101
99
102
# Setpoint is the setpoint string under
100
103
# temperatureControl/value/operationsModes/mode/setpoints, for example roomTemperature/leavingWaterOffset
101
- def __init__ (self , device , setpoint , coordinator ):
104
+ def __init__ (self , device , setpoint , coordinator , embedded_id ):
102
105
"""Initialize the climate device."""
103
106
super ().__init__ (coordinator )
104
107
_LOGGER .info (
@@ -107,9 +110,13 @@ def __init__(self, device, setpoint, coordinator):
107
110
setpoint ,
108
111
)
109
112
self ._device = device
113
+ self ._embedded_id = embedded_id
110
114
self ._setpoint = setpoint
111
- self ._attr_supported_features = self .get_supported_features ()
112
115
self ._attr_temperature_unit = UnitOfTemperature .CELSIUS
116
+ self .update_state ()
117
+
118
+ def update_state (self ) -> None :
119
+ self ._attr_supported_features = self .get_supported_features ()
113
120
self ._attr_current_temperature = self .get_current_temperature ()
114
121
self ._attr_max_temp = self .get_max_temp ()
115
122
self ._attr_min_temp = self .get_min_temp ()
@@ -126,25 +133,9 @@ def __init__(self, device, setpoint, coordinator):
126
133
127
134
@callback
128
135
def _handle_coordinator_update (self ) -> None :
129
- self ._attr_supported_features = self .get_supported_features ()
130
- self ._attr_current_temperature = self .get_current_temperature ()
131
- self ._attr_max_temp = self .get_max_temp ()
132
- self ._attr_min_temp = self .get_min_temp ()
133
- self ._attr_target_temperature_step = self .get_target_temperature_step ()
134
- self ._attr_target_temperature = self .get_target_temperature ()
135
- self ._attr_hvac_modes = self .get_hvac_modes ()
136
- self ._attr_swing_modes = self .get_swing_modes ()
137
- self ._attr_preset_modes = self .get_preset_modes ()
138
- self ._attr_fan_modes = self .get_fan_modes ()
139
- self ._attr_hvac_mode = self .get_hvac_mode ()
140
- self ._attr_swing_mode = self .get_swing_mode ()
141
- self ._attr_preset_mode = self .get_preset_mode ()
142
- self ._attr_fan_mode = self .get_fan_mode ()
136
+ self .update_state ()
143
137
self .async_write_ha_state ()
144
138
145
- async def _set (self , settings ):
146
- raise NotImplementedError
147
-
148
139
def climate_control (self ):
149
140
cc = None
150
141
supported_management_point_types = {"climateControl" }
@@ -179,29 +170,6 @@ def setpoint(self):
179
170
)
180
171
return setpoint
181
172
182
- # Return the dictionary fanControl for the current operationMode
183
- def fan_control (self ):
184
- fancontrol = None
185
- supported_management_point_types = {"climateControl" }
186
- if self ._device .daikin_data ["managementPoints" ] is not None :
187
- for management_point in self ._device .daikin_data ["managementPoints" ]:
188
- management_point_type = management_point ["managementPointType" ]
189
- if management_point_type in supported_management_point_types :
190
- # Check if we have a temperatureControl
191
- temperatureControl = management_point .get ("fanControl" )
192
- _LOGGER .info ("Climate: Device fanControl %s" , temperatureControl )
193
- if temperatureControl is not None :
194
- operationMode = management_point .get ("operationMode" ).get ("value" )
195
- fancontrol = temperatureControl ["value" ]["operationModes" ][operationMode ].get (self ._setpoint )
196
- _LOGGER .info (
197
- "Device '%s': %s operation mode %s has fanControl %s" ,
198
- self ._device .name ,
199
- self ._setpoint ,
200
- operationMode ,
201
- fancontrol ,
202
- )
203
- return fancontrol
204
-
205
173
def sensory_data (self ):
206
174
sensoryData = None
207
175
supported_management_point_types = {"climateControl" }
@@ -226,11 +194,6 @@ def sensory_data(self):
226
194
def translation_key (self ) -> str :
227
195
return "daikin_onecta"
228
196
229
- @property
230
- def embedded_id (self ):
231
- cc = self .climate_control ()
232
- return cc ["embeddedId" ]
233
-
234
197
@property
235
198
def available (self ):
236
199
"""Return the availability of the underlying device."""
@@ -355,7 +318,7 @@ async def async_set_temperature(self, **kwargs):
355
318
value = kwargs [ATTR_TEMPERATURE ]
356
319
res = await self ._device .set_path (
357
320
self ._device .getId (),
358
- self .embedded_id ,
321
+ self ._embedded_id ,
359
322
"temperatureControl" ,
360
323
f"/operationModes/{ omv } /setpoints/{ self ._setpoint } " ,
361
324
value ,
@@ -411,7 +374,7 @@ async def async_set_hvac_mode(self, hvac_mode):
411
374
412
375
# Only set the on/off to Daikin when we need to change it
413
376
if on_off_mode is not None :
414
- result &= await self ._device .set_path (self ._device .getId (), self .embedded_id , "onOffMode" , "" , on_off_mode )
377
+ result &= await self ._device .set_path (self ._device .getId (), self ._embedded_id , "onOffMode" , "" , on_off_mode )
415
378
if result is False :
416
379
_LOGGER .warning (
417
380
"Device '%s' problem setting onOffMode to %s" ,
@@ -427,7 +390,7 @@ async def async_set_hvac_mode(self, hvac_mode):
427
390
if operation_mode != cc ["operationMode" ]["value" ]:
428
391
result &= await self ._device .set_path (
429
392
self ._device .getId (),
430
- self .embedded_id ,
393
+ self ._embedded_id ,
431
394
"operationMode" ,
432
395
"" ,
433
396
operation_mode ,
@@ -442,22 +405,9 @@ async def async_set_hvac_mode(self, hvac_mode):
442
405
cc ["operationMode" ]["value" ] = operation_mode
443
406
444
407
if result is True :
445
- self ._attr_hvac_mode = hvac_mode
446
408
# When switching hvac mode it could be that we can set min/max/target/etc
447
409
# which we couldn't set with a previous hvac mode
448
- self ._attr_supported_features = self .get_supported_features ()
449
- self ._attr_current_temperature = self .get_current_temperature ()
450
- self ._attr_max_temp = self .get_max_temp ()
451
- self ._attr_min_temp = self .get_min_temp ()
452
- self ._attr_target_temperature_step = self .get_target_temperature_step ()
453
- self ._attr_target_temperature = self .get_target_temperature ()
454
- self ._attr_swing_modes = self .get_swing_modes ()
455
- self ._attr_preset_modes = self .get_preset_modes ()
456
- self ._attr_fan_modes = self .get_fan_modes ()
457
- self ._attr_swing_mode = self .get_swing_mode ()
458
- self ._attr_preset_mode = self .get_preset_mode ()
459
- self ._attr_fan_mode = self .get_fan_mode ()
460
-
410
+ self .update_state ()
461
411
self .async_write_ha_state ()
462
412
463
413
return result
@@ -522,7 +472,7 @@ async def async_set_fan_mode(self, fan_mode):
522
472
if fan_mode .isnumeric ():
523
473
res = await self ._device .set_path (
524
474
self ._device .getId (),
525
- self .embedded_id ,
475
+ self ._embedded_id ,
526
476
"fanControl" ,
527
477
f"/operationModes/{ operationmode } /fanSpeed/currentMode" ,
528
478
"fixed" ,
@@ -536,7 +486,7 @@ async def async_set_fan_mode(self, fan_mode):
536
486
new_fixed_mode = int (fan_mode )
537
487
res &= await self ._device .set_path (
538
488
self ._device .getId (),
539
- self .embedded_id ,
489
+ self ._embedded_id ,
540
490
"fanControl" ,
541
491
f"/operationModes/{ operationmode } /fanSpeed/modes/fixed" ,
542
492
new_fixed_mode ,
@@ -550,7 +500,7 @@ async def async_set_fan_mode(self, fan_mode):
550
500
else :
551
501
res = await self ._device .set_path (
552
502
self ._device .getId (),
553
- self .embedded_id ,
503
+ self ._embedded_id ,
554
504
"fanControl" ,
555
505
f"/operationModes/{ operationmode } /fanSpeed/currentMode" ,
556
506
fan_mode ,
@@ -671,7 +621,7 @@ async def async_set_swing_mode(self, swing_mode):
671
621
new_h_mode = "swing"
672
622
res &= await self ._device .set_path (
673
623
self ._device .getId (),
674
- self .embedded_id ,
624
+ self ._embedded_id ,
675
625
"fanControl" ,
676
626
f"/operationModes/{ operation_mode } /fanDirection/horizontal/currentMode" ,
677
627
new_h_mode ,
@@ -699,7 +649,7 @@ async def async_set_swing_mode(self, swing_mode):
699
649
new_v_mode = "windNice"
700
650
res &= await self ._device .set_path (
701
651
self ._device .getId (),
702
- self .embedded_id ,
652
+ self ._embedded_id ,
703
653
"fanControl" ,
704
654
f"/operationModes/{ operation_mode } /fanDirection/vertical/currentMode" ,
705
655
new_v_mode ,
@@ -735,7 +685,7 @@ async def async_set_preset_mode(self, preset_mode):
735
685
736
686
if self .preset_mode != PRESET_NONE :
737
687
current_mode = HA_PRESET_TO_DAIKIN [self .preset_mode ]
738
- result &= await self ._device .set_path (self ._device .getId (), self .embedded_id , current_mode , "" , "off" )
688
+ result &= await self ._device .set_path (self ._device .getId (), self ._embedded_id , current_mode , "" , "off" )
739
689
if result is False :
740
690
_LOGGER .warning (
741
691
"Device '%s' problem setting %s to off" ,
@@ -747,7 +697,7 @@ async def async_set_preset_mode(self, preset_mode):
747
697
if self .hvac_mode == HVACMode .OFF and preset_mode == PRESET_BOOST :
748
698
result &= await self .async_turn_on ()
749
699
750
- result &= await self ._device .set_path (self ._device .getId (), self .embedded_id , new_daikin_mode , "" , "on" )
700
+ result &= await self ._device .set_path (self ._device .getId (), self ._embedded_id , new_daikin_mode , "" , "on" )
751
701
if result is False :
752
702
_LOGGER .warning (
753
703
"Device '%s' problem setting %s to on" ,
@@ -785,7 +735,7 @@ async def async_turn_on(self):
785
735
cc = self .climate_control ()
786
736
result = True
787
737
if cc ["onOffMode" ]["value" ] == "off" :
788
- result &= await self ._device .set_path (self ._device .getId (), self .embedded_id , "onOffMode" , "" , "on" )
738
+ result &= await self ._device .set_path (self ._device .getId (), self ._embedded_id , "onOffMode" , "" , "on" )
789
739
if result is False :
790
740
_LOGGER .error ("Device '%s' problem setting onOffMode to on" , self ._device .name )
791
741
else :
@@ -805,7 +755,7 @@ async def async_turn_off(self):
805
755
cc = self .climate_control ()
806
756
result = True
807
757
if cc ["onOffMode" ]["value" ] == "on" :
808
- result &= await self ._device .set_path (self ._device .getId (), self .embedded_id , "onOffMode" , "" , "off" )
758
+ result &= await self ._device .set_path (self ._device .getId (), self ._embedded_id , "onOffMode" , "" , "off" )
809
759
if result is False :
810
760
_LOGGER .error ("Device '%s' problem setting onOffMode to off" , self ._device .name )
811
761
else :
0 commit comments