Skip to content

Commit bc97c07

Browse files
authored
Add setting to change clean count (#1457)
Adds a setting to change the number of times to clean: ``` == Configuration == Clean count (clean_count): 1 (range: 1-3) ```
1 parent 0f185f1 commit bc97c07

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

kasa/smart/modules/clean.py

+34-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
from datetime import timedelta
77
from enum import IntEnum
8-
from typing import Annotated
8+
from typing import Annotated, Literal
99

1010
from ...feature import Feature
1111
from ...module import FeatureAttribute
@@ -157,6 +157,19 @@ def _initialize_features(self) -> None:
157157
type=Feature.Type.Choice,
158158
)
159159
)
160+
self._add_feature(
161+
Feature(
162+
self._device,
163+
id="clean_count",
164+
name="Clean count",
165+
container=self,
166+
attribute_getter="clean_count",
167+
attribute_setter="set_clean_count",
168+
range_getter=lambda: (1, 3),
169+
category=Feature.Category.Config,
170+
type=Feature.Type.Number,
171+
)
172+
)
160173
self._add_feature(
161174
Feature(
162175
self._device,
@@ -283,9 +296,17 @@ async def set_fan_speed_preset(
283296
name_to_value = {x.name: x.value for x in FanSpeed}
284297
if speed not in name_to_value:
285298
raise ValueError("Invalid fan speed %s, available %s", speed, name_to_value)
286-
return await self.call(
287-
"setCleanAttr", {"suction": name_to_value[speed], "type": "global"}
288-
)
299+
return await self._change_setting("suction", name_to_value[speed])
300+
301+
async def _change_setting(
302+
self, name: str, value: int, *, scope: Literal["global", "pose"] = "global"
303+
) -> dict:
304+
"""Change device setting."""
305+
params = {
306+
name: value,
307+
"type": scope,
308+
}
309+
return await self.call("setCleanAttr", params)
289310

290311
@property
291312
def battery(self) -> int:
@@ -339,3 +360,12 @@ def clean_time(self) -> timedelta:
339360
def clean_progress(self) -> int:
340361
"""Return amount of currently cleaned area."""
341362
return self._info["clean_percent"]
363+
364+
@property
365+
def clean_count(self) -> Annotated[int, FeatureAttribute()]:
366+
"""Return number of times to clean."""
367+
return self._settings["clean_number"]
368+
369+
async def set_clean_count(self, count: int) -> Annotated[dict, FeatureAttribute()]:
370+
"""Set number of times to clean."""
371+
return await self._change_setting("clean_number", count)

tests/smart/modules/test_clean.py

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty
6969
{"suction": 1, "type": "global"},
7070
id="vacuum_fan_speed",
7171
),
72+
pytest.param(
73+
"clean_count",
74+
2,
75+
"setCleanAttr",
76+
{"clean_number": 2, "type": "global"},
77+
id="clean_count",
78+
),
7279
],
7380
)
7481
@clean

0 commit comments

Comments
 (0)