Skip to content

Commit af17544

Browse files
authored
feat: add dynamic clean modes (#437)
1 parent 251b3f9 commit af17544

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

roborock/clean_modes.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from __future__ import annotations
2+
3+
from enum import StrEnum
4+
5+
from roborock import DeviceFeatures
6+
7+
8+
class RoborockModeEnum(StrEnum):
9+
"""A custom StrEnum that also stores an integer code for each member."""
10+
11+
code: int
12+
13+
def __new__(cls, value: str, code: int) -> RoborockModeEnum:
14+
"""Creates a new enum member."""
15+
member = str.__new__(cls, value)
16+
member._value_ = value
17+
member.code = code
18+
return member
19+
20+
21+
class CleanModes(RoborockModeEnum):
22+
GENTLE = ("gentle", 105)
23+
OFF = ("off", 105)
24+
QUIET = ("quiet", 101)
25+
BALANCED = ("balanced", 102)
26+
TURBO = ("turbo", 103)
27+
MAX = ("max", 104)
28+
MAX_PLUS = ("max_plus", 108)
29+
CUSTOMIZED = ("custom", 106)
30+
SMART_MODE = ("smart_mode", 110)
31+
32+
33+
class CleanRoutes(RoborockModeEnum):
34+
STANDARD = ("standard", 300)
35+
DEEP = ("deep", 301)
36+
DEEP_PLUS = ("deep_plus", 303)
37+
FAST = ("fast", 304)
38+
DEEP_PLUS_CN = ("deep_plus", 305)
39+
SMART_MODE = ("smart_mode", 306)
40+
CUSTOMIZED = ("custom", 302)
41+
42+
43+
class CleanModesOld(RoborockModeEnum):
44+
QUIET = ("quiet", 38)
45+
BALANCED = ("balanced", 60)
46+
TURBO = ("turbo", 75)
47+
MAX = ("max", 100)
48+
49+
50+
class WaterModes(RoborockModeEnum):
51+
OFF = ("off", 200)
52+
LOW = ("low", 201)
53+
MILD = ("mild", 201)
54+
MEDIUM = ("medium", 202)
55+
STANDARD = ("standard", 202)
56+
HIGH = ("high", 203)
57+
INTENSE = ("intense", 203)
58+
CUSTOMIZED = ("custom", 204)
59+
CUSTOM = ("custom_water_flow", 207)
60+
EXTREME = ("extreme", 208)
61+
SMART_MODE = ("smart_mode", 209)
62+
63+
64+
def get_clean_modes(features: DeviceFeatures) -> list[CleanModes]:
65+
"""Get the valid clean modes for the device - also known as 'fan power' or 'suction mode'"""
66+
modes = [CleanModes.QUIET, CleanModes.BALANCED, CleanModes.TURBO, CleanModes.MAX]
67+
if features.is_max_plus_mode_supported or features.is_none_pure_clean_mop_with_max_plus:
68+
# If the vacuum has max plus mode supported
69+
modes.append(CleanModes.MAX_PLUS)
70+
if features.is_pure_clean_mop_supported:
71+
# If the vacuum is capable of 'pure mop clean' aka no vacuum
72+
modes.append(CleanModes.OFF)
73+
else:
74+
# If not, we can add gentle
75+
modes.append(CleanModes.GENTLE)
76+
return modes
77+
78+
79+
def get_clean_routes(features: DeviceFeatures, region: str) -> list[CleanRoutes]:
80+
"""The routes that the vacuum will take while mopping"""
81+
if features.is_none_pure_clean_mop_with_max_plus:
82+
return [CleanRoutes.FAST, CleanRoutes.STANDARD]
83+
supported = [CleanRoutes.STANDARD, CleanRoutes.DEEP]
84+
if features.is_careful_slow_mop_supported:
85+
if not (
86+
features.is_corner_clean_mode_supported
87+
and features.is_clean_route_deep_slow_plus_supported
88+
and region == "CN"
89+
):
90+
# for some reason there is a china specific deep plus mode
91+
supported.append(CleanRoutes.DEEP_PLUS_CN)
92+
else:
93+
supported.append(CleanRoutes.DEEP_PLUS)
94+
95+
if features.is_clean_route_fast_mode_supported:
96+
supported.append(CleanRoutes.FAST)
97+
return supported
98+
99+
100+
def get_water_modes(features: DeviceFeatures) -> list[WaterModes]:
101+
"""Get the valid water modes for the device - also known as 'water flow' or 'water level'"""
102+
supported_modes = [WaterModes.OFF]
103+
if features.is_mop_shake_module_supported:
104+
# For mops that have the vibrating mop pad, they do mild standard intense
105+
supported_modes.extend([WaterModes.MILD, WaterModes.STANDARD, WaterModes.INTENSE])
106+
else:
107+
supported_modes.extend([WaterModes.LOW, WaterModes.MEDIUM, WaterModes.HIGH])
108+
if features.is_custom_water_box_distance_supported:
109+
# This is for devices that allow you to set a custom water flow from 0-100
110+
supported_modes.append(WaterModes.CUSTOM)
111+
if features.is_mop_shake_module_supported and features.is_mop_shake_water_max_supported:
112+
supported_modes.append(WaterModes.EXTREME)
113+
return supported_modes

roborock/device_features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ class DeviceFeatures:
423423
is_clean_route_setting_supported: bool = field(
424424
metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE, ProductFeatures.MOP_SPIN_MODULE]}
425425
)
426+
is_mop_shake_module_supported: bool = field(metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE]})
426427

427428
@classmethod
428429
def from_feature_flags(

0 commit comments

Comments
 (0)