8000 Add childlock module for vacuums by rytilahti · Pull Request #1461 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add childlock module for vacuums #1461

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 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion devtools/helpers/smartrequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def get_component_requests(component_id, ver_code):
"battery": [SmartRequest.get_raw_request("getBatteryInfo")],
"consumables": [SmartRequest.get_raw_request("getConsumablesInfo")],
"direction_control": [],
"button_and_led": [],
"button_and_led": [SmartRequest.get_raw_request("getChildLockInfo")],
"speaker": [
SmartRequest.get_raw_request("getSupportVoiceLanguage"),
SmartRequest.get_raw_request("getCurrentVoiceLanguage"),
Expand Down
1 change: 1 addition & 0 deletions kasa/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Module(ABC):
ChildProtection: Final[ModuleName[smart.ChildProtection]] = ModuleName(
"ChildProtection"
)
ChildLock: Final[ModuleName[smart.ChildLock]] = ModuleName("ChildLock")
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = ModuleName("TriggerLogs")

HomeKit: Final[ModuleName[smart.HomeKit]] = ModuleName("HomeKit")
Expand Down
2 changes: 2 additions & 0 deletions kasa/smart/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .batterysensor import BatterySensor
from .brightness import Brightness
from .childdevice import ChildDevice
from .childlock import ChildLock
from .childprotection import ChildProtection
from .clean import Clean
from .cloud import Cloud
Expand Down Expand Up @@ -45,6 +46,7 @@
"Energy",
"DeviceModule",
"ChildDevice",
"ChildLock",
"BatterySensor",
"HumiditySensor",
"TemperatureSensor",
Expand Down
37 changes: 37 additions & 0 deletions kasa/smart/modules/childlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Child lock module."""

from __future__ import annotations

from ...feature import Feature
from ..smartmodule import SmartModule


class ChildLock(SmartModule):
"""Implementation for child_protection."""

REQUIRED_COMPONENT = "button_and_led"
QUERY_GETTER_NAME = "getChildLockInfo"

def _initialize_features(self) -> None:
"""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,
)
)

@property
def enabled(self) -> bool:
"""Return True if child protection is enabled."""
return self.data["child_lock_status"]

async def set_enabled(self, enabled: bool) -> dict:
"""Set child protection."""
return await self.call("setChildLockInfo", {"child_lock_status": enabled})
3 changes: 3 additions & 0 deletions tests/fixtures/smart/RV20 Max Plus(EU)_1.0_1.0.7.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
"getCarpetClean": {
"carpet_clean_prefer": "boost"
},
"getChildLockInfo": {
"child_lock_status": false
},
"getCleanAttr": {
"cistern": 2,
"clean_number": 1,
Expand Down
44 changes: 44 additions & 0 deletions tests/smart/modules/test_childlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

from kasa import Module
from kasa.smart.modules import ChildLock

from ...device_fixtures import parametrize

childlock = parametrize(
"has child lock",
component_filter="button_and_led",
protocol_filter={"SMART.CHILD"},
)


@childlock
@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: ChildLock = dev.modules[Module.ChildLock]
assert protect is not None

prop = getattr(protect, prop_name)
assert isinstance(prop, type)

feat = protect._device.features[feature]
assert feat.value == prop
assert isinstance(feat.value, type)


@childlock
async def test_enabled(dev):
"""Test the API."""
protect: ChildLock = dev.modules[Module.ChildLock]
assert protect is not None

assert isinstance(protect.enabled, bool)
await protect.set_enabled(False)
await dev.update()
assert protect.enabled is False
Loading
0