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

Add state features to iot strip sockets by sdb9696 · Pull Request #960 · 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  (2) 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
29 changes: 29 additions & 0 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 @@ -10,6 +10,7 @@
from ..device_type import DeviceType
from ..deviceconfig import DeviceConfig
from ..exceptions import KasaException
from ..feature import Feature
from ..module import Module
from ..protocol import BaseProtocol
from .iotdevice import (
Expand Down Expand Up @@ -125,6 +126,8 @@ async def update(self, update_children: bool = True):
)
for child in children
}
for child in self._children.values():
await child._initialize_features()

if update_children and self.has_emeter:
for plug in self.children:
Expand Down Expand Up @@ -250,6 +253,32 @@ async def _initialize_modules(self):
await super()._initialize_modules()
self.add_module("time", Time(self, "time"))

async def _initialize_features(self):
"""Initialize common features."""
self._add_feature(
Feature(
self,
id="state",
name="State",
attribute_getter="is_on",
attribute_setter="set_state",
type=Feature.Type.Switch,
category=Feature.Category.Primary,
)
)
self._add_feature(
Feature(
device=self,
id="on_since",
name="On since",
attribute_getter="on_since",
icon="mdi:clock",
)
)
# If the strip plug has it's own modules we should call initialize
# features for the modules here. However the _initialize_modules function
# above does not seem to be called.

async def update(self, update_children: bool = True):
"""Query the device to update the data.

Expand Down
8 changes: 8 additions & 0 deletions kasa/tests/test_strip.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 @@ -88,6 +88,14 @@ async def test_get_plug_by_index(dev: IotStrip):
dev.get_plug_by_index(len(dev.children))


@strip
async def test_plug_features(dev: IotStrip):
"""Test the child plugs have default features."""
for child in dev.children:
assert "state" in child.features
assert "on_since" in child.features


@pytest.mark.skip("this test will wear out your relays")
async def test_all_binary_states(dev):
# test every binary state
Expand Down

Back | FazBrowse Home | New Git URL