Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify fan_modes, only handle fixed special, other modes are direct… #86

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 43 additions & 60 deletions custom_components/daikin_onecta/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from .const import COORDINATOR
from .const import DAIKIN_DEVICES
from .const import DOMAIN as DAIKIN_DOMAIN
from .const import FAN_QUIET

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,13 +65,6 @@
PRESET_ECO: "econoMode",
}

DAIKIN_FAN_TO_HA = {"auto": FAN_AUTO, "quiet": FAN_QUIET}

HA_FAN_TO_DAIKIN = {
DAIKIN_FAN_TO_HA["auto"]: "auto",
DAIKIN_FAN_TO_HA["quiet"]: "quiet",
}


async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Daikin climate based on config_entry."""
Expand Down Expand Up @@ -476,36 +468,33 @@ def get_fan_mode(self):
# Check if we have a fanControl
fanControl = cc.get("fanControl")
if fanControl is not None:
operationmode = cc["operationMode"]["value"]
fanspeed = fanControl["value"]["operationModes"][operationmode]["fanSpeed"]
mode = fanspeed["currentMode"]["value"]
if mode in DAIKIN_FAN_TO_HA:
fan_mode = DAIKIN_FAN_TO_HA[mode]
else:
fsm = fanspeed.get("modes")
operation_mode = cc["operationMode"]["value"]
fan_speed = fanControl["value"]["operationModes"][operation_mode]["fanSpeed"]
mode = fan_speed["currentMode"]["value"]
if mode == "fixed":
fsm = fan_speed.get("modes")
if fsm is not None:
_LOGGER.info("FSM %s", fsm)
fixedModes = fsm[mode]
fan_mode = str(fixedModes["value"])
else:
fan_mode = mode

return fan_mode

def get_fan_modes(self):
fan_modes = []
fanspeed = None
cc = self.climate_control()
# Check if we have a fanControl
fanControl = cc.get("fanControl")
if fanControl is not None:
operationmode = cc["operationMode"]["value"]
fanspeed = fanControl["value"]["operationModes"][operationmode]["fanSpeed"]
_LOGGER.info("Found fanspeed %s", fanspeed)
for c in fanspeed["currentMode"]["values"]:
fan_control = cc.get("fanControl")
if fan_control is not None:
operation_mode = cc["operationMode"]["value"]
fan_speed = fan_control["value"]["operationModes"][operation_mode]["fanSpeed"]
_LOGGER.info("Found fanspeed %s", fan_speed)
for c in fan_speed["currentMode"]["values"]:
_LOGGER.info("Device '%s' found fan mode %s", self._device.name, c)
if c in DAIKIN_FAN_TO_HA:
fan_modes.append(DAIKIN_FAN_TO_HA[c])
else:
fsm = fanspeed.get("modes")
if c == "fixed":
fsm = fan_speed.get("modes")
if fsm is not None:
_LOGGER.info("Device '%s' found fixed %s", self._device.name, fsm)
fixedModes = fsm[c]
Expand All @@ -514,6 +503,8 @@ def get_fan_modes(self):
stepValue = int(fixedModes["stepValue"])
for val in range(minVal, maxVal + 1, stepValue):
fan_modes.append(str(val))
else:
fan_modes.append(c)

return fan_modes

Expand All @@ -528,53 +519,45 @@ async def async_set_fan_mode(self, fan_mode):
res = False
cc = self.climate_control()
operationmode = cc["operationMode"]["value"]
if fan_mode in HA_FAN_TO_DAIKIN.keys():
if fan_mode.isnumeric():
res = await self._device.set_path(
self._device.getId(),
self.embedded_id,
"fanControl",
f"/operationModes/{operationmode}/fanSpeed/currentMode",
fan_mode,
"fixed",
)
if res is False:
_LOGGER.warning(
"Device '%s' problem setting fan_mode to %s",
"Device '%s' problem setting fan_mode to fixed",
self._device.name,
fan_mode,
)

else:
if fan_mode.isnumeric():
mode = int(fan_mode)
res = await self._device.set_path(
self._device.getId(),
self.embedded_id,
"fanControl",
f"/operationModes/{operationmode}/fanSpeed/currentMode",
"fixed",
)
if res is False:
_LOGGER.warning(
"Device '%s' problem setting fan_mode to fixed",
self._device.name,
)

res &= await self._device.set_path(
self._device.getId(),
self.embedded_id,
"fanControl",
f"/operationModes/{operationmode}/fanSpeed/modes/fixed",
mode,
new_fixed_mode = int(fan_mode)
res &= await self._device.set_path(
self._device.getId(),
self.embedded_id,
"fanControl",
f"/operationModes/{operationmode}/fanSpeed/modes/fixed",
new_fixed_mode,
)
if res is False:
_LOGGER.warning(
"Device '%s' problem setting fan_mode fixed to %s",
self._device.name,
new_fixed_mode,
)
if res is False:
_LOGGER.warning(
"Device '%s' problem setting fan_mode fixed to %s",
self._device.name,
mode,
)
else:
else:
res = await self._device.set_path(
self._device.getId(),
self.embedded_id,
"fanControl",
f"/operationModes/{operationmode}/fanSpeed/currentMode",
fan_mode,
)
if res is False:
_LOGGER.warning(
"Device '%s' received invalid fan_mode %s",
"Device '%s' problem setting fan_mode to %s",
self._device.name,
fan_mode,
)
Expand Down
2 changes: 0 additions & 2 deletions custom_components/daikin_onecta/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
SENSOR_PERIOD_YEARLY: "Yearly",
}

FAN_QUIET = "quiet"

ENABLED_DEFAULT = "Enabled"
STATE_CLASS = "STATE"
ENTITY_CATEGORY = "ENTITY_CATEGORY"
Expand Down
Loading