Skip to content
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

Added number of dust collections to CleaningSummary if available #992

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/vacuum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Deleting a timer
Cleaning history
~~~~~~~~~~~~~~~~

Will also report amount of times the dust was collected if available.

::

$ mirobo cleaning-history
Expand Down
4 changes: 4 additions & 0 deletions miio/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
2 changes: 2 additions & 0 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 20 additions & 12 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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],
}
fettlaus marked this conversation as resolved.
Show resolved Hide resolved
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:
None
fettlaus marked this conversation as resolved.
Show resolved Hide resolved


class CleaningDetails(DeviceStatus):
Expand Down