| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5ab7e7e commit 589e913
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | import logging | |
| 6 | 6 | from datetime import timedelta | |
| 7 | 7 | from enum import IntEnum | |
| 8 | - from typing import Annotated | ||
| 8 | + from typing import Annotated, Literal | ||
| 9 | 9 | ||
| 10 | 10 | from ...feature import Feature | |
| 11 | 11 | from ...module import FeatureAttribute | |
@@ -157,6 +157,19 @@ def _initialize_features(self) -> None: | |||
| 157 | 157 | type=Feature.Type.Choice, | |
| 158 | 158 | ) | |
| 159 | 159 | ) | |
| 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 | + ) | ||
| 160 | 173 | self._add_feature( | |
| 161 | 174 | Feature( | |
| 162 | 175 | self._device, | |
@@ -283,9 +296,17 @@ async def set_fan_speed_preset( | |||
| 283 | 296 | name_to_value = {x.name: x.value for x in FanSpeed} | |
| 284 | 297 | if speed not in name_to_value: | |
| 285 | 298 | 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) | ||
| 289 | 310 | ||
| 290 | 311 | @property | |
| 291 | 312 | def battery(self) -> int: | |
@@ -339,3 +360,12 @@ def clean_time(self) -> timedelta: | |||
| 339 | 360 | def clean_progress(self) -> int: | |
| 340 | 361 | """Return amount of currently cleaned area.""" | |
| 341 | 362 | 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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,13 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty | |||
| 69 | 69 | {"suction": 1, "type": "global"}, | |
| 70 | 70 | id="vacuum_fan_speed", | |
| 71 | 71 | ), | |
| 72 | + pytest.param( | ||
| 73 | + "clean_count", | ||
| 74 | + 2, | ||
| 75 | + "setCleanAttr", | ||
| 76 | + {"clean_number": 2, "type": "global"}, | ||
| 77 | + id="clean_count", | ||
| 78 | + ), | ||
| 72 | 79 | ], | |
| 73 | 80 | ) | |
| 74 | 81 | @clean | |
| Back | FazBrowse Home | New Git URL |
0 commit comments