Skip to content

Commit

Permalink
Review RangeHood controls (issue #394) (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
ollo69 authored Nov 19, 2023
1 parent 6cead04 commit a5e47a8
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions custom_components/smartthinq_sensors/wideq/devices/hood.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,29 @@

ITEM_STATE_OFF = "@OV_STATE_INITIAL_W"

CTRL_BASIC = "basicCtrl"

STATE_LAMPLEVEL = "LampLevel"
STATE_VENTLEVEL = "VentLevel"

CMD_LAMPMODE = "lampOnOff"
CMD_LAMPLEVEL = "lampLevel"
CMD_VENTMODE = "ventOnOff"
CMD_VENTLEVEL = "ventLevel"

CMD_SET_VENTLAMP = "setCookStart"
CMD_SET_VENTLAMP = "setVentLamp"

KEY_DATASET = "dataSetList"
KEY_HOODSTATE = "hoodState"

CMD_VENTLAMP_DICT = {
"command": "Set",
"ctrlKey": CMD_SET_VENTLAMP,
"ctrlKey": CTRL_BASIC,
KEY_DATASET: {KEY_HOODSTATE: {}},
}

HOOD_CMD = {
CMD_SET_VENTLAMP: CMD_VENTLAMP_DICT,
}

MODE_ENABLE = "ENABLE"
MODE_DISABLE = "DISABLE"


class LightLevel(Enum):
"""The light level for a Hood device."""
Expand Down Expand Up @@ -70,21 +67,6 @@ def reset_status(self):
return self._status

# Settings
def _prepare_command_ventlamp(self):
"""Prepare vent / lamp command."""
if not self._status:
return {}

status_data = self._status.data
vent_level = status_data.get(STATE_VENTLEVEL, "0")
lamp_level = status_data.get(STATE_LAMPLEVEL, "0")
return {
CMD_VENTMODE: MODE_ENABLE if vent_level != "0" else MODE_DISABLE,
CMD_VENTLEVEL: int(vent_level),
CMD_LAMPMODE: MODE_ENABLE if lamp_level != "0" else MODE_DISABLE,
CMD_LAMPLEVEL: int(lamp_level),
}

def _prepare_command(self, ctrl_key, command, key, value):
"""
Prepare command for specific device.
Expand All @@ -93,14 +75,9 @@ def _prepare_command(self, ctrl_key, command, key, value):
if (cmd_key := HOOD_CMD.get(ctrl_key)) is None:
return None

if ctrl_key == CMD_SET_VENTLAMP:
full_cmd = self._prepare_command_ventlamp()
else:
full_cmd = {}

cmd = deepcopy(cmd_key)
def_cmd = cmd[KEY_DATASET].get(KEY_HOODSTATE, {})
cmd[KEY_DATASET][KEY_HOODSTATE] = {**def_cmd, **full_cmd, **command}
cmd[KEY_DATASET][KEY_HOODSTATE] = {**def_cmd, **command}

return cmd

Expand All @@ -125,8 +102,7 @@ async def set_light_mode(self, mode: str):
raise ValueError(f"Invalid light mode: {mode}")

level = self._supported_light_modes[mode]
status = MODE_ENABLE if level != "0" else MODE_DISABLE
cmd = {CMD_LAMPMODE: status, CMD_LAMPLEVEL: int(level)}
cmd = {CMD_LAMPLEVEL: int(level)}

await self.set(CMD_SET_VENTLAMP, cmd, key=STATE_LAMPLEVEL, value=level)

Expand All @@ -151,8 +127,7 @@ async def set_vent_speed(self, option: str):
raise ValueError(f"Invalid vent mode: {option}")

level = self._supported_vent_speeds[option]
mode = MODE_ENABLE if level != "0" else MODE_DISABLE
cmd = {CMD_VENTMODE: mode, CMD_VENTLEVEL: int(level)}
cmd = {CMD_VENTLEVEL: int(level)}

await self.set(CMD_SET_VENTLAMP, cmd, key=STATE_VENTLEVEL, value=level)

Expand Down

0 comments on commit a5e47a8

Please sign in to comment.