Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion plugwise/legacy/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ def _all_appliances(self) -> None:
continue # pragma: no cover

self._create_gw_entities(appl)
self._reorder_devices()

# Place the gateway and optional heater_central devices as 1st and 2nd
def _reorder_devices(self) -> None:
"""Place the gateway and optional heater_central devices as 1st and 2nd."""
for dev_class in PRIORITY_DEVICE_CLASSES:
for entity_id, entity in dict(self.gw_entities).items():
if entity["dev_class"] == dev_class:
Expand Down
36 changes: 22 additions & 14 deletions plugwise/smile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@
from munch import Munch


def model_to_switch_items(model: str, state: str, switch: Munch) -> tuple[str, Munch]:
"""Translate state and switch attributes based on model name.

Helper function for set_switch_state().
"""
match model:
case "dhw_cm_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "domestic_hot_water_comfort_mode"
case "cooling_ena_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "cooling_enabled"
case "lock":
switch.func = "lock"
state = "true" if state == STATE_ON else "false"

return state, switch


class SmileAPI(SmileData):
"""The Plugwise SmileAPI helper class for actual Plugwise devices."""

Expand Down Expand Up @@ -381,20 +402,7 @@ async def set_switch_state(
switch.device = "relay"
switch.func_type = "relay_functionality"
switch.func = "state"
if model == "dhw_cm_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "domestic_hot_water_comfort_mode"

if model == "cooling_ena_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "cooling_enabled"

if model == "lock":
switch.func = "lock"
state = "true" if state == STATE_ON else "false"

state, switch = model_to_switch_items(model, state, switch)
data = (
f"<{switch.func_type}>"
f"<{switch.func}>{state}</{switch.func}>"
Expand Down
Loading