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 additional sensors and settings to Roborock vacuums #1585

Merged
merged 13 commits into from
Nov 14, 2022
11 changes: 11 additions & 0 deletions miio/integrations/vacuum/roborock/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def __init__(self, *args, **kwargs):
1487548800,
],
]
self.dummies["dnd_timer"] = [
{
"enabled": 1,
"start_minute": 0,
"end_minute": 0,
"start_hour": 22,
"end_hour": 8,
}
]

self.return_values = {
"get_status": lambda x: [self.state],
Expand All @@ -75,6 +84,8 @@ def __init__(self, *args, **kwargs):
"app_zoned_clean": lambda x: self.change_mode("zoned clean"),
"app_charge": lambda x: self.change_mode("charge"),
"miIO.info": "dummy info",
"get_clean_record": lambda x: [[1488347071, 1488347123, 16, 0, 0, 0]],
"get_dnd_timer": lambda x: self.dummies["dnd_timer"],
}

super().__init__(args, kwargs)
Expand Down
135 changes: 25 additions & 110 deletions miio/integrations/vacuum/roborock/vacuum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import datetime
import enum
import json
import logging
import math
Expand All @@ -24,6 +23,22 @@
from miio.exceptions import DeviceInfoUnavailableException, UnsupportedFeatureException
from miio.interfaces import FanspeedPresets, VacuumInterface

from .vacuum_enums import (
CarpetCleaningMode,
Consumable,
DustCollectionMode,
FanspeedE2,
FanspeedEnum,
FanspeedS7,
FanspeedS7_Maxv,
FanspeedV1,
FanspeedV2,
FanspeedV3,
MopIntensity,
MopMode,
TimerState,
WaterFlow,
)
from .vacuumcontainers import (
CarpetModeStatus,
CleaningDetails,
Expand All @@ -39,112 +54,6 @@
_LOGGER = logging.getLogger(__name__)


class TimerState(enum.Enum):
On = "on"
Off = "off"


class Consumable(enum.Enum):
MainBrush = "main_brush_work_time"
SideBrush = "side_brush_work_time"
Filter = "filter_work_time"
SensorDirty = "sensor_dirty_time"


class FanspeedEnum(enum.Enum):
pass


class FanspeedV1(FanspeedEnum):
Silent = 38
Standard = 60
Medium = 77
Turbo = 90


class FanspeedV2(FanspeedEnum):
Silent = 101
Standard = 102
Medium = 103
Turbo = 104
Gentle = 105
Auto = 106


class FanspeedV3(FanspeedEnum):
Silent = 38
Standard = 60
Medium = 75
Turbo = 100


class FanspeedE2(FanspeedEnum):
# Original names from the app: Gentle, Silent, Standard, Strong, Max
Gentle = 41
Silent = 50
Standard = 68
Medium = 79
Turbo = 100


class FanspeedS7(FanspeedEnum):
Silent = 101
Standard = 102
Medium = 103
Turbo = 104


class FanspeedS7_Maxv(FanspeedEnum):
Silent = 101
Standard = 102
Medium = 103
Turbo = 104
Max = 108


class WaterFlow(enum.Enum):
"""Water flow strength on s5 max."""

Minimum = 200
Low = 201
High = 202
Maximum = 203


class MopMode(enum.Enum):
"""Mop routing on S7."""

Standard = 300
Deep = 301


class MopIntensity(enum.Enum):
"""Mop scrub intensity on S7 + S7MAXV."""

Close = 200
Mild = 201
Moderate = 202
Intense = 203


class CarpetCleaningMode(enum.Enum):
"""Type of carpet cleaning/avoidance."""

Avoid = 0
Rise = 1
Ignore = 2


class DustCollectionMode(enum.Enum):
"""Auto emptying mode (S7 + S7MAXV only)"""

Smart = 0
Quick = 1
Daily = 2
Strong = 3
Max = 4


ROCKROBO_V1 = "rockrobo.vacuum.v1"
ROCKROBO_S4 = "roborock.vacuum.s4"
ROCKROBO_S4_MAX = "roborock.vacuum.a19"
Expand Down Expand Up @@ -410,11 +319,17 @@ def manual_control(
@command()
def status(self) -> VacuumStatus:
"""Return status of the vacuum."""
status = VacuumStatus(self.send("get_status")[0])
status = self.vacuum_status()
status.embed(self.consumable_status())
status.embed(self.clean_history())
status.embed(self.dnd_status())
return status

@command()
def vacuum_status(self) -> VacuumStatus:
"""Return only status of the vacuum."""
return VacuumStatus(self.send("get_status")[0])

def enable_log_upload(self):
raise NotImplementedError("unknown parameters")
# return self.send("enable_log_upload")
Expand Down Expand Up @@ -964,7 +879,7 @@ def set_mop_mode(self, mop_mode: MopMode):
@command()
def mop_intensity(self) -> MopIntensity:
"""Get mop scrub intensity setting."""
if self.model != ROCKROBO_S7:
if self.model not in [ROCKROBO_S7, ROCKROBO_S7_MAXV]:
raise UnsupportedFeatureException(
"Mop scrub intensity not supported by %s", self.model
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
)
Expand All @@ -974,7 +889,7 @@ def mop_intensity(self) -> MopIntensity:
@command(click.argument("mop_intensity", type=EnumType(MopIntensity)))
def set_mop_intensity(self, mop_intensity: MopIntensity):
"""Set mop scrub intensity setting."""
if self.model != ROCKROBO_S7:
if self.model not in [ROCKROBO_S7, ROCKROBO_S7_MAXV]:
raise UnsupportedFeatureException(
"Mop scrub intensity not supported by %s", self.model
)
Expand Down
110 changes: 110 additions & 0 deletions miio/integrations/vacuum/roborock/vacuum_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import enum


class TimerState(enum.Enum):
On = "on"
Off = "off"


class Consumable(enum.Enum):
MainBrush = "main_brush_work_time"
SideBrush = "side_brush_work_time"
Filter = "filter_work_time"
SensorDirty = "sensor_dirty_time"


class FanspeedEnum(enum.Enum):
pass


class FanspeedV1(FanspeedEnum):
Silent = 38
Standard = 60
Medium = 77
Turbo = 90


class FanspeedV2(FanspeedEnum):
Silent = 101
Standard = 102
Medium = 103
Turbo = 104
Gentle = 105
Auto = 106


class FanspeedV3(FanspeedEnum):
Silent = 38
Standard = 60
Medium = 75
Turbo = 100


class FanspeedE2(FanspeedEnum):
# Original names from the app: Gentle, Silent, Standard, Strong, Max
Gentle = 41
Silent = 50
Standard = 68
Medium = 79
Turbo = 100


class FanspeedS7(FanspeedEnum):
Silent = 101
Standard = 102
Medium = 103
Turbo = 104


class FanspeedS7_Maxv(FanspeedEnum):
# Original names from the app: Quiet, Balanced, Turbo, Max, Max+
Off = 105
Silent = 101
Standard = 102
Medium = 103
Turbo = 104
Max = 108


class WaterFlow(enum.Enum):
"""Water flow strength on s5 max."""

Minimum = 200
Low = 201
High = 202
Maximum = 203


class MopMode(enum.Enum):
"""Mop routing on S7 + S7MAXV."""

Standard = 300
Deep = 301
DeepPlus = 303


class MopIntensity(enum.Enum):
"""Mop scrub intensity on S7 + S7MAXV."""

Off = 200
Mild = 201
Moderate = 202
Intense = 203


class CarpetCleaningMode(enum.Enum):
"""Type of carpet cleaning/avoidance."""

Avoid = 0
Rise = 1
Ignore = 2


class DustCollectionMode(enum.Enum):
"""Auto emptying mode (S7 + S7MAXV only)"""

Smart = 0
Quick = 1
Daily = 2
Strong = 3
Max = 4
Loading