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 mopping state & log a warning when encountering unknown state #784

Merged
merged 1 commit into from
Aug 3, 2020
Merged
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
12 changes: 9 additions & 3 deletions miio/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class ViomiVacuumSpeed(Enum):


class ViomiVacuumState(Enum):
Unknown = -1
IdleNotDocked = 0
Idle = 1
Idle2 = 2
Cleaning = 3
Returning = 4
Docked = 5
Mopping = 6


class ViomiMode(Enum):
Expand Down Expand Up @@ -118,12 +120,17 @@ def __init__(self, data):
@property
def state(self):
"""State of the vacuum."""
return ViomiVacuumState(self.data["run_state"])
try:
return ViomiVacuumState(self.data["run_state"])
except ValueError:
_LOGGER.warning("Unknown vacuum state: %s", self.data["run_state"])
return ViomiVacuumState.Unknown

@property
def is_on(self) -> bool:
"""True if cleaning."""
return self.state == ViomiVacuumState.Cleaning
cleaning_states = [ViomiVacuumState.Cleaning, ViomiVacuumState.Mopping]
return self.state in cleaning_states

@property
def mode(self):
Expand All @@ -141,7 +148,6 @@ def mop_type(self):
@property
def error_code(self) -> int:
"""Error code from vacuum."""

return self.data["err_state"]

@property
Expand Down