Expose current cleaning information (#1453)

Add new sensors to show the current cleaning state:
```
Cleaning area (clean_area): 0 0
Cleaning time (clean_time): 0:00:00
Cleaning progress (clean_progress): 100 %
```
This commit is contained in:
Teemu R. 2025-01-15 14:20:19 +01:00 committed by GitHub
parent 4e7e18cef1
commit 1355e85f8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 81 additions and 3 deletions

View File

@ -439,6 +439,8 @@ COMPONENT_REQUESTS = {
"clean": [ "clean": [
SmartRequest.get_raw_request("getCleanRecords"), SmartRequest.get_raw_request("getCleanRecords"),
SmartRequest.get_raw_request("getVacStatus"), SmartRequest.get_raw_request("getVacStatus"),
SmartRequest.get_raw_request("getAreaUnit"),
SmartRequest.get_raw_request("getCleanInfo"),
SmartRequest.get_raw_request("getCleanStatus"), SmartRequest.get_raw_request("getCleanStatus"),
SmartRequest("getCleanAttr", SmartRequest.GetCleanAttrParams()), SmartRequest("getCleanAttr", SmartRequest.GetCleanAttrParams()),
], ],

View File

@ -3,6 +3,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from datetime import timedelta
from enum import IntEnum from enum import IntEnum
from typing import Annotated from typing import Annotated
@ -54,6 +55,17 @@ class FanSpeed(IntEnum):
Max = 4 Max = 4
class AreaUnit(IntEnum):
"""Area unit."""
#: Square meter
Sqm = 0
#: Square feet
Sqft = 1
#: Taiwanese unit: https://en.wikipedia.org/wiki/Taiwanese_units_of_measurement#Area
Ping = 2
class Clean(SmartModule): class Clean(SmartModule):
"""Implementation of vacuum clean module.""" """Implementation of vacuum clean module."""
@ -145,6 +157,41 @@ class Clean(SmartModule):
type=Feature.Type.Choice, type=Feature.Type.Choice,
) )
) )
self._add_feature(
Feature(
self._device,
id="clean_area",
name="Cleaning area",
container=self,
attribute_getter="clean_area",
unit_getter="area_unit",
category=Feature.Category.Info,
type=Feature.Type.Sensor,
)
)
self._add_feature(
Feature(
self._device,
id="clean_time",
name="Cleaning time",
container=self,
attribute_getter="clean_time",
category=Feature.Category.Info,
type=Feature.Type.Sensor,
)
)
self._add_feature(
Feature(
self._device,
id="clean_progress",
name="Cleaning progress",
container=self,
attribute_getter="clean_progress",
unit_getter=lambda: "%",
category=Feature.Category.Info,
type=Feature.Type.Sensor,
)
)
async def _post_update_hook(self) -> None: async def _post_update_hook(self) -> None:
"""Set error code after update.""" """Set error code after update."""
@ -171,9 +218,11 @@ class Clean(SmartModule):
def query(self) -> dict: def query(self) -> dict:
"""Query to execute during the update cycle.""" """Query to execute during the update cycle."""
return { return {
"getVacStatus": None, "getVacStatus": {},
"getBatteryInfo": None, "getCleanInfo": {},
"getCleanStatus": None, "getAreaUnit": {},
"getBatteryInfo": {},
"getCleanStatus": {},
"getCleanAttr": {"type": "global"}, "getCleanAttr": {"type": "global"},
} }
@ -248,6 +297,11 @@ class Clean(SmartModule):
"""Return vac status container.""" """Return vac status container."""
return self.data["getVacStatus"] return self.data["getVacStatus"]
@property
def _info(self) -> dict:
"""Return current cleaning info."""
return self.data["getCleanInfo"]
@property @property
def _settings(self) -> dict: def _settings(self) -> dict:
"""Return cleaning settings.""" """Return cleaning settings."""
@ -265,3 +319,23 @@ class Clean(SmartModule):
except ValueError: except ValueError:
_LOGGER.warning("Got unknown status code: %s (%s)", status_code, self.data) _LOGGER.warning("Got unknown status code: %s (%s)", status_code, self.data)
return Status.UnknownInternal return Status.UnknownInternal
@property
def area_unit(self) -> AreaUnit:
"""Return area unit."""
return AreaUnit(self.data["getAreaUnit"]["area_unit"])
@property
def clean_area(self) -> Annotated[int, FeatureAttribute()]:
"""Return currently cleaned area."""
return self._info["clean_area"]
@property
def clean_time(self) -> timedelta:
"""Return current cleaning time."""
return timedelta(minutes=self._info["clean_time"])
@property
def clean_progress(self) -> int:
"""Return amount of currently cleaned area."""
return self._info["clean_percent"]

View File

@ -159,7 +159,9 @@
"getBatteryInfo": { "getBatteryInfo": {
"battery_percentage": 75 "battery_percentage": 75
}, },
"getAreaUnit": {"area_unit": 0},
"getCleanAttr": {"suction": 2, "cistern": 2, "clean_number": 1}, "getCleanAttr": {"suction": 2, "cistern": 2, "clean_number": 1},
"getCleanInfo": {"clean_time": 5, "clean_area": 5, "clean_percent": 1},
"getCleanStatus": {"getCleanStatus": {"clean_status": 0, "is_working": false, "is_mapping": false, "is_relocating": false}}, "getCleanStatus": {"getCleanStatus": {"clean_status": 0, "is_working": false, "is_mapping": false, "is_relocating": false}},
"getCleanRecords": { "getCleanRecords": {
"lastest_day_record": [ "lastest_day_record": [