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

Extend viomi vacuum support #626

Merged
merged 2 commits into from
Mar 5, 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
109 changes: 72 additions & 37 deletions miio/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@
_LOGGER = logging.getLogger(__name__)


ERROR_CODES = {
500: "Radar timed out",
501: "Wheels stuck",
502: "Low battery",
503: "Dust bin missing",
508: "Uneven ground",
509: "Cliff sensor error",
510: "Collision sensor error",
511: "Could not return to dock",
512: "Could not return to dock",
513: "Could not navigate",
514: "Vacuum stuck",
515: "Charging error",
516: "Mop temperature error",
521: "Water tank is not installed",
522: "Mop is not installed",
525: "Insufficient water in water tank",
527: "Remove mop",
528: "Dust bin missing",
529: "Mop and water tank missing",
530: "Mop and water tank missing",
531: "Water tank is not installed",
2101: "Unsufficient battery, continuing cleaning after recharge",
}


class ViomiVacuumSpeed(Enum):
Silent = 0
Standard = 1
Expand All @@ -30,10 +56,10 @@ class ViomiVacuumState(Enum):
Docked = 5


class ViomiMopMode(Enum):
Off = 0 # No Mop, Vacuum only
Mixed = 1
MopOnly = 2
class ViomiMode(Enum):
Vacuum = 0 # No Mop, Vacuum only
VacuumAndMop = 1
Mop = 2


class ViomiLanguage(Enum):
Expand All @@ -58,7 +84,19 @@ class ViomiMovementDirection(Enum):
Right = 3 # Rotate
Backward = 4
Stop = 5
# 10 is unknown
Unknown = 10


class ViomiBinType(Enum):
Vacuum = 1
Water = 2
VacuumAndWater = 3


class ViomiWaterGrade(Enum):
Low = 11
Medium = 12
High = 13


class ViomiVacuumStatus:
Expand All @@ -83,36 +121,31 @@ def is_on(self) -> bool:
def mode(self):
"""Active mode.

TODO: unknown values
TODO: is this same as mop_type property?
"""
return self.data["mode"]
return ViomiMode(self.data["mode"])

@property
def error(self):
"""Error code.
def error_code(self) -> int:
"""Error code from vacuum."""

TODO: unknown values
"""
return self.data["error_state"]

@property
def error(self) -> str:
"""String presentation for the error code."""

return ERROR_CODES.get(self.error_code, f"Unknown error {self.error_code}")

@property
def battery(self) -> int:
"""Battery in percentage."""
return self.data["battary_life"]

@property
def box_type(self):
"""Box type.

TODO: unknown values"""
return self.data["box_type"]

@property
def mop_type(self):
"""Mop type.

TODO: unknown values"""
return self.data["mop_type"]
def bin_type(self) -> ViomiBinType:
"""Type of the inserted bin."""
return ViomiBinType(self.data["box_type"])

@property
def clean_time(self) -> timedelta:
Expand All @@ -121,10 +154,7 @@ def clean_time(self) -> timedelta:

@property
def clean_area(self) -> float:
"""Cleaned area.

TODO: unknown values
"""
"""Cleaned area in square meters."""
return self.data["s_area"]

@property
Expand All @@ -133,12 +163,9 @@ def fanspeed(self) -> ViomiVacuumSpeed:
return ViomiVacuumSpeed(self.data["suction_grade"])

@property
def water_level(self):
"""Tank's water level.

TODO: unknown values, percentage?
"""
return self.data["water_grade"]
def water_grade(self) -> ViomiWaterGrade:
"""Water grade."""
return ViomiWaterGrade(self.data["water_grade"])

@property
def remember_map(self) -> bool:
Expand All @@ -156,9 +183,12 @@ def has_new_map(self) -> bool:
return bool(self.data["has_newmap"])

@property
def mop_mode(self) -> ViomiMopMode:
"""Whether mopping is enabled and if so which mode"""
return ViomiMopMode(self.data["is_mop"])
def mop_mode(self) -> ViomiMode:
"""Whether mopping is enabled and if so which mode

TODO: is this really the same as mode?
"""
return ViomiMode(self.data["is_mop"])


class ViomiVacuum(Device):
Expand Down Expand Up @@ -227,6 +257,11 @@ def set_fan_speed(self, speed: ViomiVacuumSpeed):
"""Set fanspeed [silent, standard, medium, turbo]."""
self.send("set_suction", [speed.value])

@command(click.argument("watergrade"))
def set_water_grade(self, watergrade: ViomiWaterGrade):
"""Set water grade [low, medium, high]."""
self.send("set_suction", [watergrade.value])

@command()
def home(self):
"""Return to home."""
Expand All @@ -249,7 +284,7 @@ def move(self, direction, duration=0.5):
time.sleep(0.1)
self.send("set_direction", [ViomiMovementDirection.Stop.value])

@command(click.argument("mode", type=EnumType(ViomiMopMode, False)))
@command(click.argument("mode", type=EnumType(ViomiMode, False)))
def mop_mode(self, mode):
"""Set mopping mode."""
self.send("set_mop", [mode.value])
Expand Down