8000 Fix iot strip turn on and off from parent by Obbay2 · Pull Request #639 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Fix iot strip turn on and off from parent #639

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

Merged
merged 5 commits into from
Jan 23, 2025
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
10 changes: 8 additions & 2 deletions kasa/iot/iotstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,17 @@ async def _initialize_features(self) -> None:

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

async def turn_off(self, **kwargs) -> dict:
"""Turn the strip off."""
return await self._query_helper("system", "set_relay_state", {"state": 0})
for plug in self.children:
if plug.is_on:
await plug.turn_off()
return {}

@property # type: ignore
@requires_update
Expand Down
4 changes: 0 additions & 4 deletions tests/fakeprotocol_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ def set_relay_state(self, x, child_ids=None):
child_ids = []
_LOGGER.debug("Setting relay state to %s", x["state"])

if not child_ids and "children" in self.proto["system"]["get_sysinfo"]:
for child in self.proto["system"]["get_sysinfo"]["children"]:
child_ids.append(child["id"])

_LOGGER.info("child_ids: %s", child_ids)
if child_ids:
for child in self.proto["system"]["get_sysinfo"]["children"]:
Expand Down
3 changes: 2 additions & 1 deletion tests/iot/test_iotdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ async def test_query_helper(dev):
@device_iot
@turn_on
async def test_state(dev, turn_on):
await handle_turn_on(dev, turn_on)
orig_state = dev.is_on
await handle_turn_on(dev, turn_on)
await dev.update()
if orig_state:
await dev.turn_off()
await dev.update()
Expand Down
6 changes: 5 additions & 1 deletion tests/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pytest_mock import MockerFixture

from kasa import Device, Feature, KasaException
from kasa.iot import IotStrip

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -168,7 +169,10 @@ async def _test_feature(feat, query_mock):
if feat.attribute_setter is None:
return

expecting_call = feat.id not in internal_setters
# IotStrip makes calls via it's children
expecting_call = feat.id not in internal_setters and not isinstance(
dev, IotStrip
)
Comment on lines +172 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels rather hacky, but maybe it's fine considering it's test code? Otherwise this looks good to me, but we may want to consider adding a master control for tapo strips in a separate PR to make it consistent.


if feat.type == Feature.Type.Number:
await feat.set_value(feat.minimum_value)
Expand Down
Loading
0