8000 Expose current cleaning information by rytilahti · Pull Request #1453 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Expose current cleaning information #1453

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 3 commits into from
Jan 15, 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
2 changes: 2 additions & 0 deletions devtools/helpers/smartrequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ def get_component_requests(component_id, ver_code):
"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()),
],
Expand Down
80 changes: 77 additions & 3 deletions kasa/smart/modules/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
from datetime import timedelta
from enum import IntEnum
from typing import Annotated

Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -145,6 +157,41 @@ def _initialize_features(self) -> None:
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."""
Expand All @@ -171,9 +218,11 @@ async def _post_update_hook(self) -> None:
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"},
}

Expand Down Expand Up @@ -248,6 +297,11 @@ def _vac_status(self) -> dict:
"""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."""
Expand All @@ -265,3 +319,23 @@ def status(self) -> Status:
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"]
2 changes: 2 additions & 0 deletions tests/fixtures/smart/RV20 Max Plus(EU)_1.0_1.0.7.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Loading
0