FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Expose current cleaning information by rytilahti · Pull Request #1453 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .json  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions devtools/helpers/smartrequests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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",
Comment thread
rytilahti marked this conversation as resolved.
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"]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL