30
30
from .const import COORDINATOR
31
31
from .const import DAIKIN_DEVICES
32
32
from .const import DOMAIN as DAIKIN_DOMAIN
33
- from .const import FAN_QUIET
34
33
35
34
_LOGGER = logging .getLogger (__name__ )
36
35
66
65
PRESET_ECO : "econoMode" ,
67
66
}
68
67
69
- DAIKIN_FAN_TO_HA = {"auto" : FAN_AUTO , "quiet" : FAN_QUIET }
70
-
71
- HA_FAN_TO_DAIKIN = {
72
- DAIKIN_FAN_TO_HA ["auto" ]: "auto" ,
73
- DAIKIN_FAN_TO_HA ["quiet" ]: "quiet" ,
74
- }
75
-
76
68
77
69
async def async_setup_entry (hass , entry , async_add_entities ):
78
70
"""Set up Daikin climate based on config_entry."""
@@ -476,36 +468,33 @@ def get_fan_mode(self):
476
468
# Check if we have a fanControl
477
469
fanControl = cc .get ("fanControl" )
478
470
if fanControl is not None :
479
- operationmode = cc ["operationMode" ]["value" ]
480
- fanspeed = fanControl ["value" ]["operationModes" ][operationmode ]["fanSpeed" ]
481
- mode = fanspeed ["currentMode" ]["value" ]
482
- if mode in DAIKIN_FAN_TO_HA :
483
- fan_mode = DAIKIN_FAN_TO_HA [mode ]
484
- else :
485
- fsm = fanspeed .get ("modes" )
471
+ operation_mode = cc ["operationMode" ]["value" ]
472
+ fan_speed = fanControl ["value" ]["operationModes" ][operation_mode ]["fanSpeed" ]
473
+ mode = fan_speed ["currentMode" ]["value" ]
474
+ if mode == "fixed" :
475
+ fsm = fan_speed .get ("modes" )
486
476
if fsm is not None :
487
477
_LOGGER .info ("FSM %s" , fsm )
488
478
fixedModes = fsm [mode ]
489
479
fan_mode = str (fixedModes ["value" ])
480
+ else :
481
+ fan_mode = mode
490
482
491
483
return fan_mode
492
484
493
485
def get_fan_modes (self ):
494
486
fan_modes = []
495
- fanspeed = None
496
487
cc = self .climate_control ()
497
488
# Check if we have a fanControl
498
- fanControl = cc .get ("fanControl" )
499
- if fanControl is not None :
500
- operationmode = cc ["operationMode" ]["value" ]
501
- fanspeed = fanControl ["value" ]["operationModes" ][operationmode ]["fanSpeed" ]
502
- _LOGGER .info ("Found fanspeed %s" , fanspeed )
503
- for c in fanspeed ["currentMode" ]["values" ]:
489
+ fan_control = cc .get ("fanControl" )
490
+ if fan_control is not None :
491
+ operation_mode = cc ["operationMode" ]["value" ]
492
+ fan_speed = fan_control ["value" ]["operationModes" ][operation_mode ]["fanSpeed" ]
493
+ _LOGGER .info ("Found fanspeed %s" , fan_speed )
494
+ for c in fan_speed ["currentMode" ]["values" ]:
504
495
_LOGGER .info ("Device '%s' found fan mode %s" , self ._device .name , c )
505
- if c in DAIKIN_FAN_TO_HA :
506
- fan_modes .append (DAIKIN_FAN_TO_HA [c ])
507
- else :
508
- fsm = fanspeed .get ("modes" )
496
+ if c == "fixed" :
497
+ fsm = fan_speed .get ("modes" )
509
498
if fsm is not None :
510
499
_LOGGER .info ("Device '%s' found fixed %s" , self ._device .name , fsm )
511
500
fixedModes = fsm [c ]
@@ -514,6 +503,8 @@ def get_fan_modes(self):
514
503
stepValue = int (fixedModes ["stepValue" ])
515
504
for val in range (minVal , maxVal + 1 , stepValue ):
516
505
fan_modes .append (str (val ))
506
+ else :
507
+ fan_modes .append (c )
517
508
518
509
return fan_modes
519
510
@@ -528,53 +519,45 @@ async def async_set_fan_mode(self, fan_mode):
528
519
res = False
529
520
cc = self .climate_control ()
530
521
operationmode = cc ["operationMode" ]["value" ]
531
- if fan_mode in HA_FAN_TO_DAIKIN . keys ():
522
+ if fan_mode . isnumeric ():
532
523
res = await self ._device .set_path (
533
524
self ._device .getId (),
534
525
self .embedded_id ,
535
526
"fanControl" ,
536
527
f"/operationModes/{ operationmode } /fanSpeed/currentMode" ,
537
- fan_mode ,
528
+ "fixed" ,
538
529
)
539
530
if res is False :
540
531
_LOGGER .warning (
541
- "Device '%s' problem setting fan_mode to %s " ,
532
+ "Device '%s' problem setting fan_mode to fixed " ,
542
533
self ._device .name ,
543
- fan_mode ,
544
534
)
545
535
546
- else :
547
- if fan_mode .isnumeric ():
548
- mode = int (fan_mode )
549
- res = await self ._device .set_path (
550
- self ._device .getId (),
551
- self .embedded_id ,
552
- "fanControl" ,
553
- f"/operationModes/{ operationmode } /fanSpeed/currentMode" ,
554
- "fixed" ,
555
- )
556
- if res is False :
557
- _LOGGER .warning (
558
- "Device '%s' problem setting fan_mode to fixed" ,
559
- self ._device .name ,
560
- )
561
-
562
- res &= await self ._device .set_path (
563
- self ._device .getId (),
564
- self .embedded_id ,
565
- "fanControl" ,
566
- f"/operationModes/{ operationmode } /fanSpeed/modes/fixed" ,
567
- mode ,
536
+ new_fixed_mode = int (fan_mode )
537
+ res &= await self ._device .set_path (
538
+ self ._device .getId (),
539
+ self .embedded_id ,
540
+ "fanControl" ,
541
+ f"/operationModes/{ operationmode } /fanSpeed/modes/fixed" ,
542
+ new_fixed_mode ,
543
+ )
544
+ if res is False :
545
+ _LOGGER .warning (
546
+ "Device '%s' problem setting fan_mode fixed to %s" ,
547
+ self ._device .name ,
548
+ new_fixed_mode ,
568
549
)
569
- if res is False :
570
- _LOGGER .warning (
571
- "Device '%s' problem setting fan_mode fixed to %s" ,
572
- self ._device .name ,
573
- mode ,
574
- )
575
- else :
550
+ else :
551
+ res = await self ._device .set_path (
552
+ self ._device .getId (),
553
+ self .embedded_id ,
554
+ "fanControl" ,
555
+ f"/operationModes/{ operationmode } /fanSpeed/currentMode" ,
556
+ fan_mode ,
557
+ )
558
+ if res is False :
576
559
_LOGGER .warning (
577
- "Device '%s' received invalid fan_mode %s" ,
560
+ "Device '%s' problem setting fan_mode to %s" ,
578
561
self ._device .name ,
579
562
fan_mode ,
580
563
)
0 commit comments