Skip to content

Convert carpet_clean_mode to carpet_boost switch #1486

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 26, 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
40 changes: 12 additions & 28 deletions kasa/smart/modules/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
from datetime import timedelta
from enum import IntEnum, StrEnum
from enum import IntEnum
from typing import Annotated, Literal

from ...feature import Feature
Expand Down Expand Up @@ -58,13 +58,6 @@ class FanSpeed(IntEnum):
Ultra = 5


class CarpetCleanMode(StrEnum):
"""Carpet clean mode."""

Normal = "normal"
Boost = "boost"


class AreaUnit(IntEnum):
"""Area unit."""

Expand Down Expand Up @@ -184,15 +177,14 @@ def _initialize_features(self) -> None:
self._add_feature(
Feature(
self._device,
id="carpet_clean_mode",
name="Carpet clean mode",
id="carpet_boost",
name="Carpet boost",
container=self,
attribute_getter="carpet_clean_mode",
attribute_setter="set_carpet_clean_mode",
attribute_getter="carpet_boost",
attribute_setter="set_carpet_boost",
icon="mdi:rug",
choices_getter=lambda: list(CarpetCleanMode.__members__),
category=Feature.Category.Config,
type=Feature.Type.Choice,
type=Feature.Type.Switch,
)
)
self._add_feature(
Expand Down Expand Up @@ -380,22 +372,14 @@ def status(self) -> Status:
return Status.UnknownInternal

@property
def carpet_clean_mode(self) -> Annotated[str, FeatureAttribute()]:
"""Return carpet clean mode."""
return CarpetCleanMode(self.data["getCarpetClean"]["carpet_clean_prefer"]).name
def carpet_boost(self) -> bool:
"""Return carpet boost mode."""
return self.data["getCarpetClean"]["carpet_clean_prefer"] == "boost"

async def set_carpet_clean_mode(
self, mode: str
) -> Annotated[dict, FeatureAttribute()]:
async def set_carpet_boost(self, on: bool) -> dict:
"""Set carpet clean mode."""
name_to_value = {x.name: x.value for x in CarpetCleanMode}
if mode not in name_to_value:
raise ValueError(
"Invalid carpet clean mode %s, available %s", mode, name_to_value
)
return await self.call(
"setCarpetClean", {"carpet_clean_prefer": name_to_value[mode]}
)
mode = "boost" if on else "normal"
return await self.call("setCarpetClean", {"carpet_clean_prefer": mode})

@property
def area_unit(self) -> AreaUnit:
Expand Down
15 changes: 4 additions & 11 deletions tests/smart/modules/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
("vacuum_status", "status", Status),
("vacuum_error", "error", ErrorCode),
("vacuum_fan_speed", "fan_speed_preset", str),
("carpet_clean_mode", "carpet_clean_mode", str),
("carpet_boost", "carpet_boost", bool),
("battery_level", "battery", int),
],
)
Expand Down Expand Up @@ -71,11 +71,11 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty
id="vacuum_fan_speed",
),
pytest.param(
"carpet_clean_mode",
"Boost",
"carpet_boost",
True,
"setCarpetClean",
{"carpet_clean_prefer": "boost"},
id="carpet_clean_mode",
id="carpet_boost",
),
pytest.param(
"clean_count",
Expand Down Expand Up @@ -218,13 +218,6 @@ async def test_unknown_status(
"Invalid fan speed",
id="vacuum_fan_speed",
),
pytest.param(
"carpet_clean_mode",
"invalid mode",
ValueError,
"Invalid carpet clean mode",
id="carpet_clean_mode",
),
],
)
async def test_invalid_settings(
Expand Down
Loading