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

WIP: Vacuum: Provide human readable fan speeds #468

Closed
wants to merge 1 commit into from
Closed
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
59 changes: 51 additions & 8 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

_LOGGER = logging.getLogger(__name__)

MODEL_VACUUM_V1 = 'rockrobo.vacuum.v1'
MODEL_VACUUM_S5 = 'roborock.vacuum.s5'

MODELS_SUPPORTED = [MODEL_VACUUM_V1, MODEL_VACUUM_S5]


class VacuumException(DeviceException):
pass
Expand All @@ -39,12 +44,35 @@ class Consumable(enum.Enum):
SensorDirty = "sensor_dirty_time"


class FanSpeedS5(enum.Enum):
Quiet = 101
Balanced = 102
Turbo = 103
Max = 104
Mop = 105


class FanSpeed(enum.Enum):
Quiet = 38
Balanced = 60
Turbo = 77
Max = 90


class Vacuum(Device):
"""Main class representing the vacuum."""

def __init__(self, ip: str, token: str = None, start_id: int = 0,
debug: int = 0) -> None:
super().__init__(ip, token, start_id, debug)
debug: int = 0, lazy_discover: bool = True,
model: str = MODEL_VACUUM_V1) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover)

if model in MODELS_SUPPORTED:
self.model = model
else:
self.model = MODEL_VACUUM_V1
_LOGGER.error("Device model %s unsupported. Falling back to %s.", model, self.model)

self.manual_seqnum = -1

@command()
Expand Down Expand Up @@ -306,19 +334,34 @@ def disable_dnd(self):
return self.send("close_dnd_timer", [""])

@command(
click.argument("speed", type=int),
click.argument("speed", type=str),
)
def set_fan_speed(self, speed: int):
def set_fan_speed(self, speed: str):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to pass a Enum here. @rytilahti any suggestions?

"""Set fan speed.

:param int speed: Fan speed to set"""
# speed = [38, 60 or 77]
return self.send("set_custom_mode", [speed])
:param str speed: Fan speed to set"""

speed = speed.title()
if self.model == MODEL_VACUUM_S5:
return self.send("set_custom_mode", [FanSpeedS5[speed]])

return self.send("set_custom_mode", [FanSpeed[speed]])

@command()
def fan_speed(self):
"""Return fan speed."""
return self.send("get_custom_mode")[0]
speed = self.send("get_custom_mode")[0]
if self.model == MODEL_VACUUM_S5:
return FanSpeedS5(speed)

return FanSpeed(speed)

def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
if self.model == MODEL_VACUUM_S5:
return [speed for speed in FanSpeedS5]

return [speed for speed in FanSpeed]

@command()
def sound_info(self):
Expand Down