Skip to content

Commit

Permalink
Check for empty cleaning_history instead of crashing on it (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti authored Feb 3, 2019
1 parent bce9a29 commit 420c1c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,15 @@ def clean_history(self) -> CleaningSummary:
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(0)
def last_clean_details(self) -> Optional[CleaningDetails]:
"""Return details from the last cleaning.
Returns None if there has been no cleanups."""
history = self.clean_history()
if not history.ids:
return None

last_clean_id = history.ids.pop(0)
return self.clean_details(last_clean_id, return_list=False)

@command(
Expand Down

0 comments on commit 420c1c7

Please sign in to comment.