16
16
from homeassistant .components .climate .const import PRESET_COMFORT
17
17
from homeassistant .components .climate .const import PRESET_ECO
18
18
from homeassistant .components .climate .const import PRESET_NONE
19
- from homeassistant .components .climate .const import SWING_BOTH
20
- from homeassistant .components .climate .const import SWING_HORIZONTAL
21
- from homeassistant .components .climate .const import SWING_OFF
22
- from homeassistant .components .climate .const import SWING_VERTICAL
23
19
from homeassistant .const import ATTR_TEMPERATURE
24
20
from homeassistant .const import CONF_HOST
25
21
from homeassistant .const import CONF_NAME
31
27
from .const import DAIKIN_DEVICES
32
28
from .const import DOMAIN as DAIKIN_DOMAIN
33
29
from .const import FANMODE_FIXED
34
- from .const import SWING_COMFORT
35
- from .const import SWING_COMFORT_HORIZONTAL
36
- from .const import SWING_FLOOR
37
- from .const import SWING_FLOOR_HORIZONTAL
38
30
39
31
_LOGGER = logging .getLogger (__name__ )
40
32
@@ -133,10 +125,12 @@ def update_state(self) -> None:
133
125
self ._attr_target_temperature = self .get_target_temperature ()
134
126
self ._attr_hvac_modes = self .get_hvac_modes ()
135
127
self ._attr_swing_modes = self .get_swing_modes ()
128
+ self ._attr_swing_horizontal_modes = self .get_swing_horizontal_modes ()
136
129
self ._attr_preset_modes = self .get_preset_modes ()
137
130
self ._attr_fan_modes = self .get_fan_modes ()
138
131
self ._attr_hvac_mode = self .get_hvac_mode ()
139
132
self ._attr_swing_mode = self .get_swing_mode ()
133
+ self ._attr_swing_horizontal_mode = self .get_swing_horizontal_mode ()
140
134
self ._attr_preset_mode = self .get_preset_mode ()
141
135
self ._attr_fan_mode = self .get_fan_mode ()
142
136
self ._attr_device_info = self ._device .device_info ()
@@ -225,8 +219,12 @@ def get_supported_features(self):
225
219
if operationmodedict is not None :
226
220
if operationmodedict .get ("fanSpeed" ) is not None :
227
221
supported_features |= ClimateEntityFeature .FAN_MODE
228
- if operationmodedict .get ("fanDirection" ) is not None :
229
- supported_features |= ClimateEntityFeature .SWING_MODE
222
+ fan_direction = operationmodedict .get ("fanDirection" )
223
+ if fan_direction is not None :
224
+ if fan_direction .get ("vertical" ) is not None :
225
+ supported_features |= ClimateEntityFeature .SWING_MODE
226
+ if fan_direction .get ("horizontal" ) is not None :
227
+ supported_features |= ClimateEntityFeature .SWING_HORIZONTAL_MODE
230
228
231
229
_LOGGER .info ("Device '%s' supports features %s" , self ._device .name , supported_features )
232
230
@@ -558,90 +556,64 @@ async def async_set_fan_mode(self, fan_mode):
558
556
559
557
return res
560
558
561
- def get_swing_mode (self ):
562
- swingMode = None
559
+ def __get_swing_mode (self , direction ):
560
+ swingMode = ""
563
561
cc = self .climate_control ()
564
562
fanControl = cc .get ("fanControl" )
565
- h = SWING_OFF
566
- v = SWING_OFF
567
563
if fanControl is not None :
568
- swingMode = SWING_OFF
569
564
operationmode = cc ["operationMode" ]["value" ]
570
565
operationmodedict = fanControl ["value" ]["operationModes" ].get (operationmode )
571
566
if operationmodedict is not None :
572
567
fan_direction = operationmodedict .get ("fanDirection" )
573
568
if fan_direction is not None :
574
- horizontal = fan_direction .get ("horizontal" )
575
- vertical = fan_direction .get ("vertical" )
576
- if horizontal is not None :
577
- h = horizontal ["currentMode" ]["value" ]
578
- if vertical is not None :
579
- v = vertical ["currentMode" ]["value" ]
580
- if h == "swing" :
581
- swingMode = SWING_HORIZONTAL
582
- if v == "swing" :
583
- swingMode = SWING_VERTICAL
584
- if v == "swing" and h == "swing" :
585
- swingMode = SWING_BOTH
586
- if v == "floorHeatingAirflow" :
587
- if h == "swing" :
588
- swingMode = SWING_FLOOR_HORIZONTAL
589
- else :
590
- swingMode = SWING_FLOOR
591
- if v == "windNice" :
592
- if h == "swing" :
593
- swingMode = SWING_COMFORT_HORIZONTAL
594
- else :
595
- swingMode = SWING_COMFORT
569
+ fd = fan_direction .get (direction )
570
+ if fd is not None :
571
+ swingMode = fd ["currentMode" ]["value" ].lower ()
596
572
597
573
_LOGGER .info (
598
- "Device '%s' has swing mode '%s', determined from h:%s v:%s " ,
574
+ "Device '%s' has %s swing mode '%s'" ,
599
575
self ._device .name ,
576
+ direction ,
600
577
swingMode ,
601
- h ,
602
- v ,
603
578
)
604
579
605
580
return swingMode
606
581
607
- def get_swing_modes (self ):
582
+ def get_swing_mode (self ):
583
+ return self .__get_swing_mode ("vertical" )
584
+
585
+ def get_swing_horizontal_mode (self ):
586
+ return self .__get_swing_mode ("horizontal" )
587
+
588
+ def __get_swing_modes (self , direction ):
608
589
swingModes = []
609
590
cc = self .climate_control ()
610
591
fanControl = cc .get ("fanControl" )
611
592
if fanControl is not None :
612
- swingModes = [SWING_OFF ]
593
+ swingModes = []
613
594
operationmode = cc ["operationMode" ]["value" ]
614
595
operationmodedict = fanControl ["value" ]["operationModes" ].get (operationmode )
615
596
if operationmodedict is not None :
616
597
fanDirection = operationmodedict .get ("fanDirection" )
617
598
if fanDirection is not None :
618
- horizontal = fanDirection .get ("horizontal" )
619
- vertical = fanDirection .get ("vertical" )
620
- if horizontal is not None :
621
- for mode in horizontal ["currentMode" ]["values" ]:
622
- if mode == "swing" :
623
- swingModes .append (SWING_HORIZONTAL )
599
+ vertical = fanDirection .get (direction )
624
600
if vertical is not None :
625
601
for mode in vertical ["currentMode" ]["values" ]:
626
- if mode == "swing" :
627
- swingModes .append (SWING_VERTICAL )
628
- if horizontal is not None :
629
- swingModes .append (SWING_BOTH )
630
- if mode == "floorHeatingAirflow" :
631
- swingModes .append (SWING_FLOOR )
632
- if horizontal is not None :
633
- swingModes .append (SWING_FLOOR_HORIZONTAL )
634
- if mode == "windNice" :
635
- swingModes .append (SWING_COMFORT )
636
- if horizontal is not None :
637
- swingModes .append (SWING_COMFORT_HORIZONTAL )
638
- _LOGGER .info ("Device '%s' support swing modes %s" , self ._device .name , swingModes )
602
+ swingModes .append (mode .lower ())
603
+ _LOGGER .info ("Device '%s' support %s swing modes %s" , self ._device .name , direction , swingModes )
639
604
return swingModes
640
605
641
- async def async_set_swing_mode (self , swing_mode ):
606
+ def get_swing_modes (self ):
607
+ return self .__get_swing_modes ("vertical" )
608
+
609
+ def get_swing_horizontal_modes (self ):
610
+ return self .__get_swing_modes ("horizontal" )
611
+
612
+ async def __set_swing (self , direction , swing_mode ):
642
613
_LOGGER .debug (
643
- "Device '%s' request to set swing_mode to %s" ,
614
+ "Device '%s' request to set swing %s mode to %s" ,
644
615
self ._device .name ,
616
+ direction ,
645
617
swing_mode ,
646
618
)
647
619
res = True
@@ -652,51 +624,61 @@ async def async_set_swing_mode(self, swing_mode):
652
624
operation_mode = cc ["operationMode" ]["value" ]
653
625
fan_direction = fan_control ["value" ]["operationModes" ][operation_mode ].get ("fanDirection" )
654
626
if fan_direction is not None :
655
- horizontal = fan_direction .get ("horizontal" )
656
- vertical = fan_direction .get ("vertical" )
657
- if horizontal is not None :
658
- new_h_mode = "stop"
659
- if swing_mode in (SWING_HORIZONTAL , SWING_BOTH , SWING_COMFORT_HORIZONTAL , SWING_FLOOR_HORIZONTAL ):
660
- new_h_mode = "swing"
661
- res &= await self ._device .patch (
627
+ fd = fan_direction .get (direction )
628
+ if fd is not None :
629
+ new_mode = "stop"
630
+ # For translation the current mode is always lower case, but we need to send
631
+ # the daikin mixed case mode, so search that
632
+ for mode in fd ["currentMode" ]["values" ]:
633
+ if swing_mode == mode .lower ():
634
+ new_mode = mode
635
+ res = await self ._device .patch (
662
636
self ._device .id ,
663
637
self ._embedded_id ,
664
638
"fanControl" ,
665
- f"/operationModes/{ operation_mode } /fanDirection/horizontal /currentMode" ,
666
- new_h_mode ,
639
+ f"/operationModes/{ operation_mode } /fanDirection/{ direction } /currentMode" ,
640
+ new_mode ,
667
641
)
668
642
if res is False :
669
643
_LOGGER .warning (
670
- "Device '%s' problem setting horizontal swing mode to %s" ,
644
+ "Device '%s' problem setting %s swing mode to %s" ,
671
645
self ._device .name ,
672
- new_h_mode ,
646
+ direction ,
647
+ new_mode ,
673
648
)
649
+ return res
674
650
675
- if vertical is not None :
676
- new_v_mode = "stop"
677
- if swing_mode in (SWING_VERTICAL , SWING_BOTH ):
678
- new_v_mode = "swing"
679
- if swing_mode in (SWING_FLOOR , SWING_FLOOR_HORIZONTAL ):
680
- new_v_mode = "floorHeatingAirflow"
681
- if swing_mode in (SWING_COMFORT , SWING_COMFORT_HORIZONTAL ):
682
- new_v_mode = "windNice"
683
- res &= await self ._device .patch (
684
- self ._device .id ,
685
- self ._embedded_id ,
686
- "fanControl" ,
687
- f"/operationModes/{ operation_mode } /fanDirection/vertical/currentMode" ,
688
- new_v_mode ,
689
- )
690
- if res is False :
691
- _LOGGER .warning (
692
- "Device '%s' problem setting vertical swing mode to %s" ,
693
- self ._device .name ,
694
- new_v_mode ,
695
- )
651
+ async def async_set_swing_mode (self , swing_mode ):
652
+ res = True
653
+ if self .swing_mode != swing_mode :
654
+ res = await self .__set_swing ("vertical" , swing_mode )
696
655
697
- if res is True :
698
- self ._attr_swing_mode = swing_mode
699
- self .async_write_ha_state ()
656
+ if res is True :
657
+ self ._attr_swing_mode = swing_mode
658
+ self .async_write_ha_state ()
659
+ else :
660
+ _LOGGER .debug (
661
+ "Device '%s' request to set vertical swing mode '%s' ignored already set" ,
662
+ self ._device .name ,
663
+ swing_mode ,
664
+ )
665
+
666
+ return res
667
+
668
+ async def async_set_swing_horizontal_mode (self , swing_mode ):
669
+ res = True
670
+ if self .swing_horizontal_mode != swing_mode :
671
+ res = await self .__set_swing ("horizontal" , swing_mode )
672
+
673
+ if res is True :
674
+ self ._attr_swing_horizontal_mode = swing_mode
675
+ self .async_write_ha_state ()
676
+ else :
677
+ _LOGGER .debug (
678
+ "Device '%s' request to set horizontal swing mode '%s' ignored already set" ,
679
+ self ._device .name ,
680
+ swing_mode ,
681
+ )
700
682
701
683
return res
702
684
0 commit comments