Skip to content

Commit d088bb1

Browse files
committed
Correct switch state input
1 parent 8e66e47 commit d088bb1

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

plugwise/legacy/smile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
OFF,
1919
REQUIRE_APPLIANCES,
2020
RULES,
21+
STATE_ON,
2122
GwEntityData,
2223
ThermoLoc,
2324
)
@@ -241,7 +242,7 @@ async def set_switch_state(
241242
For group switches, sets the state for each member in the group separately.
242243
For switch-locks, sets the lock state using a different data format.
243244
"""
244-
req_state = state == "true"
245+
req_state = state == STATE_ON
245246
switch = Munch()
246247
switch.actuator = "actuator_functionalities"
247248
switch.func_type = "relay_functionality"
@@ -251,7 +252,7 @@ async def set_switch_state(
251252

252253
# Handle switch-lock
253254
if model == "lock":
254-
state = "false" if state == "off" else "true"
255+
state = "true" if state == STATE_ON else "false"
255256
appliance = self._appliances.find(f'appliance[@id="{appl_id}"]')
256257
appl_name = appliance.find("name").text
257258
appl_type = appliance.find("type").text
@@ -295,7 +296,7 @@ async def _set_groupswitch_member_state(
295296
296297
Set the given State of the relevant Switch (relay) within a group of members.
297298
"""
298-
req_state = state == "true"
299+
req_state = state == STATE_ON
299300
switched = 0
300301
for member in members:
301302
if not self.gw_entities[member]["switches"]["lock"]:

plugwise/smile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
NOTIFICATIONS,
2323
OFF,
2424
RULES,
25+
STATE_ON,
2526
GwEntityData,
2627
ThermoLoc,
2728
)
@@ -379,7 +380,7 @@ async def set_switch_state(
379380
self, appl_id: str, members: list[str] | None, model: str, state: str
380381
) -> bool:
381382
"""Set the given State of the relevant Switch."""
382-
req_state = state == "true"
383+
req_state = state == STATE_ON
383384
switch = Munch()
384385
switch.actuator = "actuator_functionalities"
385386
switch.device = "relay"
@@ -397,7 +398,7 @@ async def set_switch_state(
397398

398399
if model == "lock":
399400
switch.func = "lock"
400-
state = "false" if state == "off" else "true"
401+
state = "true" if state == STATE_ON else "false"
401402

402403
if members is not None:
403404
return await self._set_groupswitch_member_state(members, state, switch)
@@ -433,7 +434,7 @@ async def _set_groupswitch_member_state(
433434
434435
Set the given State of the relevant Switch within a group of members.
435436
"""
436-
req_state = state == "true"
437+
req_state = state == STATE_ON
437438
switched = 0
438439
for member in members:
439440
locator = f'appliance[@id="{member}"]/{switch.actuator}/{switch.func_type}'

tests/test_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,9 @@ async def tinker_switch(
684684
"""Turn a Switch on and off to test functionality."""
685685
_LOGGER.info("Asserting modifying settings for switch devices:")
686686
_LOGGER.info("- Devices (%s):", dev_id)
687-
convert = {"true": True, "false": False}
687+
convert = {"on": True, "off": False}
688688
tinker_switch_passed = False
689-
for new_state in ["false", "true", "false"]:
689+
for new_state in ["off", "on", "off"]:
690690
_LOGGER.info("- Switching %s", new_state)
691691
try:
692692
result = await smile.set_switch_state(dev_id, members, model, new_state)

0 commit comments

Comments
 (0)