FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix iot strip turn on and off from parent by Obbay2 · Pull Request #639 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 8 additions & 2 deletions kasa/iot/iotstrip.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Back | FazBrowse Home | New Git URL