Skip to content

Commit

Permalink
Added number of dust collections to CleaningSummary if available (ryt…
Browse files Browse the repository at this point in the history
…ilahti#992)

* added number of dust collections to CleaningSummary

* added hint to documentation

* Update miio/vacuumcontainers.py

Co-authored-by: Teemu R. <tpr@iki.fi>

Co-authored-by: Teemu R. <tpr@iki.fi>
  • Loading branch information
2 people authored and xvlady committed May 9, 2021
1 parent 393dc39 commit e30429f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
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],
}
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):
Expand Down

0 comments on commit e30429f

Please sign in to comment.