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

Add last_clean_details to return information from the last clean #395

Merged
merged 2 commits into from
Oct 31, 2018
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
32 changes: 27 additions & 5 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import pathlib
import time
from typing import List
from typing import List, Optional, Union

import click
import pytz
Expand Down Expand Up @@ -184,17 +184,39 @@ def clean_history(self) -> CleaningSummary:
"""Return generic cleaning history."""
return CleaningSummary(self.send("get_clean_summary"))

@command()
def last_clean_details(self) -> CleaningDetails:
"""Return details from the last cleaning."""
last_clean_id = self.clean_history().ids.pop()
return self.clean_details(last_clean_id, return_list=False)

@command(
click.argument("id_", type=int, metavar="ID"),
click.argument("return_list", type=bool, default=False)
)
def clean_details(self, id_: int) -> List[CleaningDetails]:
def clean_details(self, id_: int, return_list=True) -> Union[
List[CleaningDetails],
Optional[CleaningDetails]]:
"""Return details about specific cleaning."""
details = self.send("get_clean_record", [id_])

res = list()
for rec in details:
res.append(CleaningDetails(rec))
if not details:
_LOGGER.warning("No cleaning record found for id %s" % id_)
return None

if return_list:
_LOGGER.warning("This method will be returning the details "
"without wrapping them into a list in the "
"near future. The current behavior can be "
"kept by passing return_list=True and this "
"warning will be removed when the default gets "
"changed.")
return [CleaningDetails(entry) for entry in details]

if len(details) > 1:
_LOGGER.warning("Got multiple clean details, returning the first")

res = CleaningDetails(details.pop())
return res

@command()
Expand Down
18 changes: 9 additions & 9 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,15 @@ def cleaning_history(vac: miio.Vacuum):
res.total_area))
click.echo()
for idx, id_ in enumerate(res.ids):
for e in vac.clean_details(id_):
color = "green" if e.complete else "yellow"
click.echo(click.style(
"Clean #%s: %s-%s (complete: %s, error: %s)" % (
idx, e.start, e.end, e.complete, e.error),
bold=True, fg=color))
click.echo(" Area cleaned: %s m²" % e.area)
click.echo(" Duration: (%s)" % e.duration)
click.echo()
details = vac.clean_details(id_, return_list=False)
color = "green" if details.complete else "yellow"
click.echo(click.style(
"Clean #%s: %s-%s (complete: %s, error: %s)" % (
idx, details.start, details.end, details.complete, details.error),
bold=True, fg=color))
click.echo(" Area cleaned: %s m²" % details.area)
click.echo(" Duration: (%s)" % details.duration)
click.echo()


@cli.command()
Expand Down