From e30429fa98231879ed85ad301e4dd93f04f504fa Mon Sep 17 00:00:00 2001 From: Fettlaus <80817+fettlaus@users.noreply.github.com> Date: Thu, 8 Apr 2021 22:31:15 +0200 Subject: [PATCH] Added number of dust collections to CleaningSummary if available (#992) * added number of dust collections to CleaningSummary * added hint to documentation * Update miio/vacuumcontainers.py Co-authored-by: Teemu R. Co-authored-by: Teemu R. --- docs/vacuum.rst | 2 ++ miio/tests/test_vacuum.py | 4 ++++ miio/vacuum_cli.py | 2 ++ miio/vacuumcontainers.py | 32 ++++++++++++++++++++------------ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/docs/vacuum.rst b/docs/vacuum.rst index 085a510e4..6c5604270 100644 --- a/docs/vacuum.rst +++ b/docs/vacuum.rst @@ -117,6 +117,8 @@ Deleting a timer Cleaning history ~~~~~~~~~~~~~~~~ +Will also report amount of times the dust was collected if available. + :: $ mirobo cleaning-history diff --git a/miio/tests/test_vacuum.py b/miio/tests/test_vacuum.py index ccf1871ef..7ab44ee69 100644 --- a/miio/tests/test_vacuum.py +++ b/miio/tests/test_vacuum.py @@ -194,6 +194,8 @@ def test_history(self): days=2, seconds=1345 ) + assert self.device.clean_history().dust_collection_count is None + def test_history_dict(self): with patch.object( self.device, @@ -217,3 +219,5 @@ def test_history_dict(self): assert self.device.clean_history().total_duration == datetime.timedelta( days=2, seconds=1345 ) + + assert self.device.clean_history().dust_collection_count == 5 diff --git a/miio/vacuum_cli.py b/miio/vacuum_cli.py index 5c995ffa8..7817d1db0 100644 --- a/miio/vacuum_cli.py +++ b/miio/vacuum_cli.py @@ -438,6 +438,8 @@ def cleaning_history(vac: miio.Vacuum): res = vac.clean_history() click.echo("Total clean count: %s" % res.count) click.echo("Cleaned for: %s (area: %s m²)" % (res.total_duration, res.total_area)) + if res.dust_collection_count is not None: + click.echo("Emptied dust collection bin: %s times" % res.dust_collection_count) click.echo() for idx, id_ in enumerate(res.ids): details = vac.clean_details(id_, return_list=False) diff --git a/miio/vacuumcontainers.py b/miio/vacuumcontainers.py index 17e8cc13b..83e14007b 100644 --- a/miio/vacuumcontainers.py +++ b/miio/vacuumcontainers.py @@ -1,7 +1,7 @@ # -*- coding: UTF-8 -*# from datetime import datetime, time, timedelta from enum import IntEnum -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Optional, Union from croniter import croniter @@ -192,35 +192,43 @@ def __init__(self, data: Union[List[Any], Dict[str, Any]]) -> None: # 1487894400, 1487808000, 1487548800 ] ], # "id": 1 } # newer models return a dict - if type(data) is dict: - self.data = [ - data["clean_time"], - data["clean_area"], - data["clean_count"], - data["records"], - ] + if type(data) is list: + self.data = { + "clean_time": data[0], + "clean_area": data[1], + "clean_count": data[2], + "records": data[3], + } else: self.data = data @property def total_duration(self) -> timedelta: """Total cleaning duration.""" - return pretty_seconds(self.data[0]) + return pretty_seconds(self.data["clean_time"]) @property def total_area(self) -> float: """Total cleaned area.""" - return pretty_area(self.data[1]) + return pretty_area(self.data["clean_area"]) @property def count(self) -> int: """Number of cleaning runs.""" - return int(self.data[2]) + return int(self.data["clean_count"]) @property def ids(self) -> List[int]: """A list of available cleaning IDs, see also :class:`CleaningDetails`.""" - return list(self.data[3]) + return list(self.data["records"]) + + @property + def dust_collection_count(self) -> Optional[int]: + """Total number of dust collections.""" + if "dust_collection_count" in self.data: + return int(self.data["dust_collection_count"]) + else: + return None class CleaningDetails(DeviceStatus):