-
-
Notifications
You must be signed in to change notification settings - Fork 239
Add childprotection module #1141
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2309e0b
Add childprotection module
rytilahti bb6bbee
Merge remote-tracking branch 'upstream/master' into feat/childprotection
rytilahti e841fb3
Read child_lock state from the main sysinfo
rytilahti cdaca06
Add tests
rytilahti 6e4d20f
Set category
rytilahti ee4e38c
Handle review comments
rytilahti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Child lock module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ...feature import Feature | ||
| from ..smartmodule import SmartModule | ||
|
|
||
|
|
||
| class ChildProtection(SmartModule): | ||
| """Implementation for child_protection.""" | ||
|
|
||
| REQUIRED_COMPONENT = "child_protection" | ||
| QUERY_GETTER_NAME = "get_child_protection" | ||
|
|
||
| def _initialize_features(self): | ||
| """Initialize features after the initial update.""" | ||
| self._add_feature( | ||
| Feature( | ||
| device=self._device, | ||
| id="child_lock", | ||
| name="Child lock", | ||
| container=self, | ||
| attribute_getter="enabled", | ||
| attribute_setter="set_enabled", | ||
| type=Feature.Type.Switch, | ||
| category=Feature.Category.Config, | ||
| ) | ||
| ) | ||
|
|
||
| def query(self) -> dict: | ||
| """Query to execute during the update cycle.""" | ||
| return {} | ||
|
|
||
| @property | ||
| def enabled(self) -> bool: | ||
| """Return True if child protection is enabled.""" | ||
| return self.data["child_protection"] | ||
|
|
||
| async def set_enabled(self, enabled: bool) -> dict: | ||
| """Set child protection.""" | ||
| return await self.call("set_child_protection", {"enable": enabled}) |
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
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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import pytest | ||
|
|
||
| from kasa import Module | ||
| from kasa.smart.modules import ChildProtection | ||
| from kasa.tests.device_fixtures import parametrize | ||
|
|
||
| child_protection = parametrize( | ||
| "has child protection", | ||
| component_filter="child_protection", | ||
| protocol_filter={"SMART.CHILD"}, | ||
| ) | ||
|
|
||
|
|
||
| @child_protection | ||
| @pytest.mark.parametrize( | ||
| ("feature", "prop_name", "type"), | ||
| [ | ||
| ("child_lock", "enabled", bool), | ||
| ], | ||
| ) | ||
| async def test_features(dev, feature, prop_name, type): | ||
| """Test that features are registered and work as expected.""" | ||
| protect: ChildProtection = dev.modules[Module.ChildProtection] | ||
| assert protect is not None | ||
|
|
||
| prop = getattr(protect, prop_name) | ||
| assert isinstance(prop, type) | ||
|
|
||
| feat = protect._device.features[feature] | ||
| assert feat.value == prop | ||
rytilahti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert isinstance(feat.value, type) | ||
|
|
||
|
|
||
| @child_protection | ||
| async def test_enabled(dev): | ||
| """Test the API.""" | ||
| protect: ChildProtection = dev.modules[Module.ChildProtection] | ||
| assert protect is not None | ||
|
|
||
| assert isinstance(protect.enabled, bool) | ||
| await protect.set_enabled(False) | ||
| await dev.update() | ||
| assert protect.enabled is False | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.