| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| 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}) |
| 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 | ||
|
Comment thread
rytilahti marked this conversation as 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 | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.