mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 00:26:25 +00:00
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:
parent
4e7e18cef1
commit
1355e85f8e
@ -439,6 +439,8 @@ COMPONENT_REQUESTS = {
|
||||
"clean": [
|
||||
SmartRequest.get_raw_request("getCleanRecords"),
|
||||
SmartRequest.get_raw_request("getVacStatus"),
|
||||
SmartRequest.get_raw_request("getAreaUnit"),
|
||||
SmartRequest.get_raw_request("getCleanInfo"),
|
||||
SmartRequest.get_raw_request("getCleanStatus"),
|
||||
SmartRequest("getCleanAttr", SmartRequest.GetCleanAttrParams()),
|
||||
],
|
||||
|
@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
from enum import IntEnum
|
||||
from typing import Annotated
|
||||
|
||||
@ -54,6 +55,17 @@ class FanSpeed(IntEnum):
|
||||
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):
|
||||
"""Implementation of vacuum clean module."""
|
||||
|
||||
@ -145,6 +157,41 @@ class Clean(SmartModule):
|
||||
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:
|
||||
"""Set error code after update."""
|
||||
@ -171,9 +218,11 @@ class Clean(SmartModule):
|
||||
def query(self) -> dict:
|
||||
"""Query to execute during the update cycle."""
|
||||
return {
|
||||
"getVacStatus": None,
|
||||
"getBatteryInfo": None,
|
||||
"getCleanStatus": None,
|
||||
"getVacStatus": {},
|
||||
"getCleanInfo": {},
|
||||
"getAreaUnit": {},
|
||||
"getBatteryInfo": {},
|
||||
"getCleanStatus": {},
|
||||
"getCleanAttr": {"type": "global"},
|
||||
}
|
||||
|
||||
@ -248,6 +297,11 @@ class Clean(SmartModule):
|
||||
"""Return vac status container."""
|
||||
return self.data["getVacStatus"]
|
||||
|
||||
@property
|
||||
def _info(self) -> dict:
|
||||
"""Return current cleaning info."""
|
||||
return self.data["getCleanInfo"]
|
||||
|
||||
@property
|
||||
def _settings(self) -> dict:
|
||||
"""Return cleaning settings."""
|
||||
@ -265,3 +319,23 @@ class Clean(SmartModule):
|
||||
except ValueError:
|
||||
_LOGGER.warning("Got unknown status code: %s (%s)", status_code, self.data)
|
||||
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"]
|
||||
|
@ -159,7 +159,9 @@
|
||||
"getBatteryInfo": {
|
||||
"battery_percentage": 75
|
||||
},
|
||||
"getAreaUnit": {"area_unit": 0},
|
||||
"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}},
|
||||
"getCleanRecords": {
|
||||
"lastest_day_record": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user