Convert carpet_clean_mode to carpet_boost switch (#1486)

This commit is contained in:
Teemu R. 2025-01-26 17:16:24 +01:00 committed by GitHub
parent 1df05af208
commit 781d07f6a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 39 deletions

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import logging import logging
from datetime import timedelta from datetime import timedelta
from enum import IntEnum, StrEnum from enum import IntEnum
from typing import Annotated, Literal from typing import Annotated, Literal
from ...feature import Feature from ...feature import Feature
@ -58,13 +58,6 @@ class FanSpeed(IntEnum):
Ultra = 5 Ultra = 5
class CarpetCleanMode(StrEnum):
"""Carpet clean mode."""
Normal = "normal"
Boost = "boost"
class AreaUnit(IntEnum): class AreaUnit(IntEnum):
"""Area unit.""" """Area unit."""
@ -184,15 +177,14 @@ class Clean(SmartModule):
self._add_feature( self._add_feature(
Feature( Feature(
self._device, self._device,
id="carpet_clean_mode", id="carpet_boost",
name="Carpet clean mode", name="Carpet boost",
container=self, container=self,
attribute_getter="carpet_clean_mode", attribute_getter="carpet_boost",
attribute_setter="set_carpet_clean_mode", attribute_setter="set_carpet_boost",
icon="mdi:rug", icon="mdi:rug",
choices_getter=lambda: list(CarpetCleanMode.__members__),
category=Feature.Category.Config, category=Feature.Category.Config,
type=Feature.Type.Choice, type=Feature.Type.Switch,
) )
) )
self._add_feature( self._add_feature(
@ -380,22 +372,14 @@ class Clean(SmartModule):
return Status.UnknownInternal return Status.UnknownInternal
@property @property
def carpet_clean_mode(self) -> Annotated[str, FeatureAttribute()]: def carpet_boost(self) -> bool:
"""Return carpet clean mode.""" """Return carpet boost mode."""
return CarpetCleanMode(self.data["getCarpetClean"]["carpet_clean_prefer"]).name return self.data["getCarpetClean"]["carpet_clean_prefer"] == "boost"
async def set_carpet_clean_mode( async def set_carpet_boost(self, on: bool) -> dict:
self, mode: str
) -> Annotated[dict, FeatureAttribute()]:
"""Set carpet clean mode.""" """Set carpet clean mode."""
name_to_value = {x.name: x.value for x in CarpetCleanMode} mode = "boost" if on else "normal"
if mode not in name_to_value: return await self.call("setCarpetClean", {"carpet_clean_prefer": mode})
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]}
)
@property @property
def area_unit(self) -> AreaUnit: def area_unit(self) -> AreaUnit:

View File

@ -21,7 +21,7 @@ clean = parametrize("clean module", component_filter="clean", protocol_filter={"
("vacuum_status", "status", Status), ("vacuum_status", "status", Status),
("vacuum_error", "error", ErrorCode), ("vacuum_error", "error", ErrorCode),
("vacuum_fan_speed", "fan_speed_preset", str), ("vacuum_fan_speed", "fan_speed_preset", str),
("carpet_clean_mode", "carpet_clean_mode", str), ("carpet_boost", "carpet_boost", bool),
("battery_level", "battery", int), ("battery_level", "battery", int),
], ],
) )
@ -71,11 +71,11 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty
id="vacuum_fan_speed", id="vacuum_fan_speed",
), ),
pytest.param( pytest.param(
"carpet_clean_mode", "carpet_boost",
"Boost", True,
"setCarpetClean", "setCarpetClean",
{"carpet_clean_prefer": "boost"}, {"carpet_clean_prefer": "boost"},
id="carpet_clean_mode", id="carpet_boost",
), ),
pytest.param( pytest.param(
"clean_count", "clean_count",
@ -218,13 +218,6 @@ async def test_unknown_status(
"Invalid fan speed", "Invalid fan speed",
id="vacuum_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( async def test_invalid_settings(