Skip to content

Commit

Permalink
Vacuum: add resume_zoned_clean() and resume_or_start() helper (#473)
Browse files Browse the repository at this point in the history
First take on fixing #471. resume_or_start() can be used to either unpause
or start a new cleanup depending on the state of the vacuum.
  • Loading branch information
rytilahti authored Feb 26, 2019
1 parent ea98223 commit 4d8dcd6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def pause(self):
"""Pause cleaning."""
return self.send("app_pause")

@command()
def resume_or_start(self):
"""A shortcut for resuming or starting cleaning."""
status = self.status()
if status.in_zone_cleaning and status.is_paused:
return self.resume_zoned_clean()

return self.start()

@command()
def home(self):
"""Stop cleaning and return home."""
Expand All @@ -95,6 +104,11 @@ def zoned_clean(self, zones: List):
:param List zones: List of zones to clean: [[x1,y1,x2,y2, iterations],[x1,y1,x2,y2, iterations]]"""
return self.send("app_zoned_clean", zones)

@command()
def resume_zoned_clean(self):
"""Resume zone cleaning after being paused."""
return self.send("resume_zoned_clean")

@command()
def manual_start(self):
"""Start manual control mode."""
Expand Down
10 changes: 10 additions & 0 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ def in_cleaning(self) -> bool:
# we are not using in_cleaning as it does not seem to work properly.
# return bool(self.data["in_cleaning"])

@property
def in_zone_cleaning(self) -> bool:
"""Return True if the vacuum is in zone cleaning mode."""
return self.data["in_cleaning"] == 2

@property
def is_paused(self) -> bool:
"""Return True if vacuum is paused."""
return self.state_code == 10

@property
def is_on(self) -> bool:
"""True if device is currently cleaning (either automatic, manual,
Expand Down

0 comments on commit 4d8dcd6

Please sign in to comment.