8000 Add childlock module for vacuums (#1461) · Fulch36/python-kasa@980f6a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 980f6a3

Browse files
rytilahtisdb9696
andauthored
Add childlock module for vacuums (python-kasa#1461)
Add new configuration feature: ``` Child lock (child_lock): False ``` --------- Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
1 parent 773801c commit 980f6a3

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

devtools/helpers/smartrequests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def get_component_requests(component_id, ver_code):
448448
"battery": [SmartRequest.get_raw_request("getBatteryInfo")],
449449
"consumables": [SmartRequest.get_raw_request("getConsumablesInfo")],
450450
"direction_control": [],
451-
"button_and_led": [],
451+
"button_and_led": [SmartRequest.get_raw_request("getChildLockInfo")],
452452
"speaker": [
453453
SmartRequest.get_raw_request("getSupportVoiceLanguage"),
454454
SmartRequest.get_raw_request("getCurrentVoiceLanguage"),

kasa/module.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class Module(ABC):
152152
ChildProtection: Final[ModuleName[smart.ChildProtection]] = ModuleName(
153153
"ChildProtection"
154154
)
155+
ChildLock: Final[ModuleName[smart.ChildLock]] = ModuleName("ChildLock")
155156
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = ModuleName("TriggerLogs")
156157

157158
HomeKit: Final[ModuleName[smart.HomeKit]] = ModuleName("HomeKit")

kasa/smart/modules/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .batterysensor import BatterySensor
77
from .brightness import Brightness
88
from .childdevice import ChildDevice
9+
from .childlock import ChildLock
910
from .childprotection import ChildProtection
1011
from .clean import Clean
1112
from .cloud import Cloud
@@ -45,6 +46,7 @@
4546
"Energy",
4647
"DeviceModule",
4748
"ChildDevice",
49+
"ChildLock",
4850
"BatterySensor",
4951
"HumiditySensor",
5052
"TemperatureSensor",

kasa/smart/modules/childlock.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Child lock module."""
2+
3+
from __future__ import annotations
4+
5+
from ...feature import Feature
6+
from ..smartmodule import SmartModule
7+
8+
9+
class ChildLock(SmartModule):
10+
"""Implementation for child lock."""
11+
12+
REQUIRED_COMPONENT = "button_and_led"
13+
QUERY_GETTER_NAME = "getChildLockInfo"
14+
15+
def _initialize_features(self) -> None:
16+
"""Initialize features after the initial update."""
17+
self._add_feature(
18+
Feature(
19+
device=self._device,
20+
id="child_lock",
21+
name="Child lock",
22+
container=self,
23+
attribute_getter="enabled",
24+
attribute_setter="set_enabled",
25+
type=Feature.Type.Switch,
26+
category=Feature.Category.Config,
27+
)
28+
)
29+
30+
@property
31+
def enabled(self) -> bool:
32+
"""Return True if child lock is enabled."""
33+
return self.data["child_lock_status"]
34+
35+
async def set_enabled(self, enabled: bool) -> dict:
36+
"""Set child lock."""
37+
return await self.call("setChildLockInfo", {"child_lock_status": enabled})

tests/fixtures/smart/RV20 Max Plus(EU)_1.0_1.0.7.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@
165165
"getCarpetClean": {
166166
"carpet_clean_prefer": "boost"
167167
},
168+
"getChildLockInfo": {
169+
"child_lock_status": false
170+
},
168171
"getCleanAttr": {
169172
"cistern": 2,
170173
"clean_number": 1,

tests/smart/modules/test_childlock.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
from kasa import Module
4+
from kasa.smart.modules import ChildLock
5+
6+
from ...device_fixtures import parametrize
7+
8+
childlock = parametrize(
9+
"has child lock",
10+
component_filter="button_and_led",
11+
protocol_filter={"SMART"},
12+
)
13+
14+
15+
@childlock
16+
@pytest.mark.parametrize(
17+
("feature", "prop_name", "type"),
18+
[
19+
("child_lock", "enabled", bool),
20+
],
21+
)
22+
async def test_features(dev, feature, prop_name, type):
23+
"""Test that features are registered and work as expected."""
24+
protect: ChildLock = dev.modules[Module.ChildLock]
25+
assert protect is not None
26+
27+
prop = getattr(protect, prop_name)
28+
assert isinstance(prop, type)
29+
30+
feat = protect._device.features[feature]
31+
assert feat.value == prop
32+
assert isinstance(feat.value, type)
33+
34+
35+
@childlock
36+
async def test_enabled(dev):
37+
"""Test the API."""
38+
protect: ChildLock = dev.modules[Module.ChildLock]
39+
assert protect is not None
40+
41+
assert isinstance(protect.enabled, bool)
42+
await protect.set_enabled(False)
43+
await dev.update()
44+
assert protect.enabled is False

0 commit comments

Comments
 (0)
0