8000 Fix iot strip turn on and off from parent (#639) · ryenitcher/python-kasa@b701441 · GitHub
[go: up one dir, main page]

Skip to content

Commit b701441

Browse files
Obbay2sdb9696
andauthored
Fix iot strip turn on and off from parent (python-kasa#639)
Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
1 parent b6a5849 commit b701441

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

kasa/iot/iotstrip.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,17 @@ async def _initialize_features(self) -> None:
161161

162162
async def turn_on(self, **kwargs) -> dict:
163163
"""Turn the strip on."""
164-
return await self._query_helper("system", "set_relay_state", {"state": 1})
164+
for plug in self.children:
165+
if plug.is_off:
166+
await plug.turn_on()
167+
return {}
165168

166169
async def turn_off(self, **kwargs) -> dict:
167170
"""Turn the strip off."""
168-
return await self._query_helper("system", "set_relay_state", {"state": 0})
171+
for plug in self.children:
172+
if plug.is_on:
173+
await plug.turn_off()
174+
return {}
169175

170176
@property # type: ignore
171177
@requires_update

tests/fakeprotocol_iot.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,6 @@ def set_relay_state(self, x, child_ids=None):
308308
child_ids = []
309309
_LOGGER.debug("Setting relay state to %s", x["state"])
310310

311-
if not child_ids and "children" in self.proto["system"]["get_sysinfo"]:
312-
for child in self.proto["system"]["get_sysinfo"]["children"]:
313-
child_ids.append(child["id"])
314-
315311
_LOGGER.info("child_ids: %s", child_ids)
316312
if child_ids:
317313
for child in self.proto["system"]["get_sysinfo"]["children"]:

tests/iot/test_iotdevice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ async def test_query_helper(dev):
137137
@device_iot
138138
@turn_on
139139
async def test_state(dev, turn_on):
140-
await handle_turn_on(dev, turn_on)
141140
orig_state = dev.is_on
141+
await handle_turn_on(dev, turn_on)
142+
await dev.update()
142143
if orig_state:
143144
await dev.turn_off()
144145
await dev.update()

tests/test_feature.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pytest_mock import MockerFixture
66

77
from kasa import Device, Feature, KasaException
8+
from kasa.iot import IotStrip
89

910
_LOGGER = logging.getLogger(__name__)
1011

@@ -168,7 +169,10 @@ async def _test_feature(feat, query_mock):
168169
if feat.attribute_setter is None:
169170
return
170171

171-
expecting_call = feat.id not in internal_setters
172+
# IotStrip makes calls via it's children
173+
expecting_call = feat.id not in internal_setters and not isinstance(
174+
dev, IotStrip
175+
)
172176

173177
if feat.type == Feature.Type.Number:
174178
await feat.set_value(feat.minimum_value)

0 commit comments

Comments
 (0)
0