Skip to content

Commit 7dd8b88

Browse files
committed
Simplify fan_modes, only handle fixed special, other modes are directly passed back to HA
* custom_components/daikin_onecta/climate.py: * custom_components/daikin_onecta/const.py:
1 parent 5555a52 commit 7dd8b88

File tree

2 files changed

+43
-62
lines changed

2 files changed

+43
-62
lines changed

custom_components/daikin_onecta/climate.py

+43-60
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from .const import COORDINATOR
3131
from .const import DAIKIN_DEVICES
3232
from .const import DOMAIN as DAIKIN_DOMAIN
33-
from .const import FAN_QUIET
3433

3534
_LOGGER = logging.getLogger(__name__)
3635

@@ -66,13 +65,6 @@
6665
PRESET_ECO: "econoMode",
6766
}
6867

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-
7668

7769
async def async_setup_entry(hass, entry, async_add_entities):
7870
"""Set up Daikin climate based on config_entry."""
@@ -476,36 +468,33 @@ def get_fan_mode(self):
476468
# Check if we have a fanControl
477469
fanControl = cc.get("fanControl")
478470
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")
486476
if fsm is not None:
487477
_LOGGER.info("FSM %s", fsm)
488478
fixedModes = fsm[mode]
489479
fan_mode = str(fixedModes["value"])
480+
else:
481+
fan_mode = mode
490482

491483
return fan_mode
492484

493485
def get_fan_modes(self):
494486
fan_modes = []
495-
fanspeed = None
496487
cc = self.climate_control()
497488
# 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"]:
504495
_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")
509498
if fsm is not None:
510499
_LOGGER.info("Device '%s' found fixed %s", self._device.name, fsm)
511500
fixedModes = fsm[c]
@@ -514,6 +503,8 @@ def get_fan_modes(self):
514503
stepValue = int(fixedModes["stepValue"])
515504
for val in range(minVal, maxVal + 1, stepValue):
516505
fan_modes.append(str(val))
506+
else:
507+
fan_modes.append(c)
517508

518509
return fan_modes
519510

@@ -528,53 +519,45 @@ async def async_set_fan_mode(self, fan_mode):
528519
res = False
529520
cc = self.climate_control()
530521
operationmode = cc["operationMode"]["value"]
531-
if fan_mode in HA_FAN_TO_DAIKIN.keys():
522+
if fan_mode.isnumeric():
532523
res = await self._device.set_path(
533524
self._device.getId(),
534525
self.embedded_id,
535526
"fanControl",
536527
f"/operationModes/{operationmode}/fanSpeed/currentMode",
537-
fan_mode,
528+
"fixed",
538529
)
539530
if res is False:
540531
_LOGGER.warning(
541-
"Device '%s' problem setting fan_mode to %s",
532+
"Device '%s' problem setting fan_mode to fixed",
542533
self._device.name,
543-
fan_mode,
544534
)
545535

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,
568549
)
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:
576559
_LOGGER.warning(
577-
"Device '%s' received invalid fan_mode %s",
560+
"Device '%s' problem setting fan_mode to %s",
578561
self._device.name,
579562
fan_mode,
580563
)

custom_components/daikin_onecta/const.py

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
SENSOR_PERIOD_YEARLY: "Yearly",
3838
}
3939

40-
FAN_QUIET = "quiet"
41-
4240
ENABLED_DEFAULT = "Enabled"
4341
STATE_CLASS = "STATE"
4442
ENTITY_CATEGORY = "ENTITY_CATEGORY"

0 commit comments

Comments
 (0)