Skip to content

Add setting to change clean count #1457

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 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 34 additions & 4 deletions kasa/smart/modules/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from datetime import timedelta
from enum import IntEnum
from typing import Annotated
from typing import Annotated, Literal

from ...feature import Feature
from ...module import FeatureAttribute
Expand Down Expand Up @@ -157,6 +157,19 @@ def _initialize_features(self) -> None:
type=Feature.Type.Choice,
)
)
self._add_feature(
Feature(
self._device,
id="clean_count",
name="Clean count",
container=self,
attribute_getter="clean_count",
attribute_setter="set_clean_count",
range_getter=lambda: (1, 3),
category=Feature.Category.Config,
type=Feature.Type.Number,
)
)
self._add_feature(
Feature(
self._device,
Expand Down Expand Up @@ -283,9 +296,17 @@ async def set_fan_speed_preset(
name_to_value = {x.name: x.value for x in FanSpeed}
if speed not in name_to_value:
raise ValueError("Invalid fan speed %s, available %s", speed, name_to_value)
return await self.call(
"setCleanAttr", {"suction": name_to_value[speed], "type": "global"}
)
return await self._change_setting("suction", name_to_value[speed])

async def _change_setting(
self, name: str, value: int, *, scope: Literal["global", "pose"] = "global"
) -> dict:
"""Change device setting."""
params = {
name: value,
"type": scope,
}
return await self.call("setCleanAttr", params)

@property
def battery(self) -> int:
Expand Down Expand Up @@ -339,3 +360,12 @@ def clean_time(self) -> timedelta:
def clean_progress(self) -> int:
"""Return amount of currently cleaned area."""
return self._info["clean_percent"]

@property
def clean_count(self) -> Annotated[int, FeatureAttribute()]:
"""Return number of times to clean."""
return self._settings["clean_number"]

async def set_clean_count(self, count: int) -> Annotated[dict, FeatureAttribute()]:
"""Set number of times to clean."""
return await self._change_setting("clean_number", count)
7 changes: 7 additions & 0 deletions tests/smart/modules/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty
{"suction": 1, "type": "global"},
id="vacuum_fan_speed",
),
pytest.param(
"clean_count",
2,
"setCleanAttr",
{"clean_number": 2, "type": "global"},
id="clean_count",
),
],
)
@clean
Expand Down
Loading