From 36d899e5f8b3ee9b9ce8ca4082bae411d317af9e Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Sun, 1 Dec 2019 22:05:48 +0100 Subject: [PATCH 1/6] STYJ02YM: Add support to switch mop mode --- miio/viomivacuum.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index 9893ecc4b..be3e4c619 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -29,6 +29,12 @@ class ViomiVacuumState(Enum): Docked = 5 +class ViomiMopMode(Enum): + Off = 0 # No Mop, Vacuum only + Mixed = 1 + MopOnly = 2 + + class ViomiLanguage(Enum): CN = 1 # Chinese (default) EN = 2 # English @@ -140,9 +146,8 @@ def has_new_map(self) -> bool: return bool(self.data["has_newmap"]) @property - def is_mop(self) -> bool: - """True if mopping.""" - return bool(self.data["is_mop"]) + def is_mop(self) -> ViomiMopMode: + return ViomiMopMode(self.data["is_mop"]) class ViomiVacuum(Device): @@ -216,6 +221,11 @@ def home(self): """Return to home.""" self.send("set_charge", [1]) + @command(click.argument("mode", type=EnumType(ViomiMopMode, False))) + def mop_mode(self, mode): + """Set mopping mode.""" + self.send("set_mop", [mode.value]) + @command() def dnd_status(self): """Returns do-not-disturb status.""" From 3fb7be4ce2da1c94e6008a3a723b366d1b839d99 Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Sun, 1 Dec 2019 22:07:15 +0100 Subject: [PATCH 2/6] Use EnumFlag for viomivacuum.set_fan_speed --- miio/viomivacuum.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index be3e4c619..9554be01b 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -211,10 +211,10 @@ def pause(self): """Pause cleaning.""" self.send("set_mode_withroom", [0, 2, 0]) - @command(click.argument("speed", type=str)) - def set_fan_speed(self, speed: str): + @command(click.argument("speed", type=EnumType(ViomiVacuumSpeed, False))) + def set_fan_speed(self, speed: ViomiVacuumSpeed): """Set fanspeed [silent, standard, medium, turbo].""" - self.send("set_suction", [ViomiVacuumSpeed(speed.capitalize()).value]) + self.send("set_suction", [speed.value]) @command() def home(self): From 3120efad824d34b972f4e762480bd0fde275b549 Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Sun, 1 Dec 2019 22:52:10 +0100 Subject: [PATCH 3/6] STYJ02YM: Add support for manual movements. --- miio/viomivacuum.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index 9554be01b..883bc95ba 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -1,10 +1,11 @@ +import click import logging +import time + from collections import defaultdict from datetime import timedelta from enum import Enum -import click - from .click_common import EnumType, command, format_output from .device import Device from .utils import pretty_seconds @@ -51,6 +52,15 @@ class ViomiCarpetTurbo(Enum): Turbo = 2 +class ViomiMovementDirection(Enum): + Forward = 1 + Left = 2 # Rotate + Right = 3 # Rotate + Backward = 4 + Stop = 5 + # 10 is unknown + + class ViomiVacuumStatus: def __init__(self, data): # ["run_state","mode","err_state","battary_life","box_type","mop_type","s_time","s_area", @@ -221,6 +231,18 @@ def home(self): """Return to home.""" self.send("set_charge", [1]) + @command( + click.argument("direction", type=EnumType(ViomiMovementDirection, False)), + click.option('--duration', type=float, default=.5, help='number of seconds to perform this movement'), + ) + def move(self, direction, duration=.5): + """Manual movement.""" + start = time.time() + while time.time() - start < duration: + self.send("set_direction", [direction.value]) + time.sleep(.1) + self.send("set_direction", [ViomiMovementDirection.Stop.value]) + @command(click.argument("mode", type=EnumType(ViomiMopMode, False))) def mop_mode(self, mode): """Set mopping mode.""" From a4c0ca4533bd04cf0f1295595fdb15ffce674568 Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Wed, 18 Dec 2019 13:52:39 +0100 Subject: [PATCH 4/6] Rename is_mop to mop_mode --- miio/viomivacuum.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index 883bc95ba..9a33d62bd 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -156,7 +156,8 @@ def has_new_map(self) -> bool: return bool(self.data["has_newmap"]) @property - def is_mop(self) -> ViomiMopMode: + def mop_mode(self) -> ViomiMopMode: + """Whether mopping is enabled and if so which mode""" return ViomiMopMode(self.data["is_mop"]) @@ -179,7 +180,7 @@ class ViomiVacuum(Device): "Remember map: {result.remember_map}\n" "Has map: {result.has_map}\n" "Has new map: {result.has_new_map}\n" - "Is mop: {result.is_mop}\n", + "Mop mode: {result.mop_mode}\n", ) ) def status(self) -> ViomiVacuumStatus: From 758fa19ade752bb612103652e4d757fbedf3e6a0 Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Wed, 18 Dec 2019 14:00:04 +0100 Subject: [PATCH 5/6] Run black code formatter --- miio/viomivacuum.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index 9a33d62bd..4b7bf085c 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -234,14 +234,19 @@ def home(self): @command( click.argument("direction", type=EnumType(ViomiMovementDirection, False)), - click.option('--duration', type=float, default=.5, help='number of seconds to perform this movement'), + click.option( + "--duration", + type=float, + default=0.5, + help="number of seconds to perform this movement", + ), ) - def move(self, direction, duration=.5): + def move(self, direction, duration=0.5): """Manual movement.""" start = time.time() while time.time() - start < duration: - self.send("set_direction", [direction.value]) - time.sleep(.1) + self.send("set_direction", [direction.value]) + time.sleep(0.1) self.send("set_direction", [ViomiMovementDirection.Stop.value]) @command(click.argument("mode", type=EnumType(ViomiMopMode, False))) From 045fcb607d2d07c8fcef816d16f17527d5e3fd70 Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Wed, 18 Dec 2019 14:03:27 +0100 Subject: [PATCH 6/6] Run isort --- miio/viomivacuum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miio/viomivacuum.py b/miio/viomivacuum.py index 4b7bf085c..85f1175d6 100644 --- a/miio/viomivacuum.py +++ b/miio/viomivacuum.py @@ -1,11 +1,11 @@ -import click import logging import time - from collections import defaultdict from datetime import timedelta from enum import Enum +import click + from .click_common import EnumType, command, format_output from .device import Device from .utils import pretty_seconds