Skip to content
Open
Show file tree
Hide file tree
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
58 changes: 49 additions & 9 deletions roborock/clean_modes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from roborock import DeviceFeatures

from .code_mappings import RoborockModeEnum
from .device_features import DeviceFeatures


class CleanModes(RoborockModeEnum):
class VacuumModes(RoborockModeEnum):
GENTLE = ("gentle", 105)
OFF = ("off", 105)
QUIET = ("quiet", 101)
Expand Down Expand Up @@ -48,18 +47,40 @@ class WaterModes(RoborockModeEnum):
SMART_MODE = ("smart_mode", 209)


def get_clean_modes(features: DeviceFeatures) -> list[CleanModes]:
class WashTowelModes(RoborockModeEnum):
SMART = ("smart", 10)
LIGHT = ("light", 0)
BALANCED = ("balanced", 1)
DEEP = ("deep", 2)
SUPER_DEEP = ("super_deep", 8)


def get_wash_towel_modes(features: DeviceFeatures) -> list[WashTowelModes]:
"""Get the valid wash towel modes for the device"""
modes = [WashTowelModes.LIGHT, WashTowelModes.BALANCED, WashTowelModes.DEEP]
if features.is_super_deep_wash_supported and not features.is_dirty_replenish_clean_supported:
modes.append(WashTowelModes.SUPER_DEEP)
elif features.is_dirty_replenish_clean_supported:
modes.append(WashTowelModes.SMART)
return modes


def get_clean_modes(features: DeviceFeatures) -> list[VacuumModes]:
"""Get the valid clean modes for the device - also known as 'fan power' or 'suction mode'"""
modes = [CleanModes.QUIET, CleanModes.BALANCED, CleanModes.TURBO, CleanModes.MAX]
modes = [VacuumModes.QUIET, VacuumModes.BALANCED, VacuumModes.TURBO, VacuumModes.MAX]
if features.is_max_plus_mode_supported or features.is_none_pure_clean_mop_with_max_plus:
# If the vacuum has max plus mode supported
modes.append(CleanModes.MAX_PLUS)
modes.append(VacuumModes.MAX_PLUS)
if features.is_pure_clean_mop_supported:
# If the vacuum is capable of 'pure mop clean' aka no vacuum
modes.append(CleanModes.OFF)
modes.append(VacuumModes.OFF)
else:
# If not, we can add gentle
modes.append(CleanModes.GENTLE)
modes.append(VacuumModes.GENTLE)
if features.is_smart_clean_mode_set_supported:
modes.append(VacuumModes.SMART_MODE)
if features.is_customized_clean_supported:
modes.append(VacuumModes.CUSTOMIZED)
return modes


Expand All @@ -72,7 +93,7 @@ def get_clean_routes(features: DeviceFeatures, region: str) -> list[CleanRoutes]
if not (
features.is_corner_clean_mode_supported
and features.is_clean_route_deep_slow_plus_supported
and region == "CN"
and region == "cn"
):
# for some reason there is a china specific deep plus mode
supported.append(CleanRoutes.DEEP_PLUS_CN)
Expand All @@ -81,6 +102,11 @@ def get_clean_routes(features: DeviceFeatures, region: str) -> list[CleanRoutes]

if features.is_clean_route_fast_mode_supported:
supported.append(CleanRoutes.FAST)
if features.is_smart_clean_mode_set_supported:
supported.append(CleanRoutes.SMART_MODE)
if features.is_customized_clean_supported:
supported.append(CleanRoutes.CUSTOMIZED)

return supported


Expand All @@ -97,4 +123,18 @@ def get_water_modes(features: DeviceFeatures) -> list[WaterModes]:
supported_modes.append(WaterModes.CUSTOM)
if features.is_mop_shake_module_supported and features.is_mop_shake_water_max_supported:
supported_modes.append(WaterModes.EXTREME)
if features.is_smart_clean_mode_set_supported:
supported_modes.append(WaterModes.SMART_MODE)
if features.is_customized_clean_supported:
supported_modes.append(WaterModes.CUSTOMIZED)

return supported_modes


def is_smart_mode_set(water_mode: WaterModes, clean_mode: VacuumModes, mop_mode: CleanRoutes) -> bool:
"""Check if the smart mode is set for the given water mode and clean mode"""
return (
water_mode == WaterModes.SMART_MODE
or clean_mode == VacuumModes.SMART_MODE
or mop_mode == CleanRoutes.SMART_MODE
)
57 changes: 51 additions & 6 deletions roborock/device_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,45 @@ class ProductFeatures(StrEnum):
NEW_DEFAULT_FEATURES = [ProductFeatures.REMOTE_BACK, ProductFeatures.CLEANMODE_MAXPLUS]


PEARL_FEATURES = NEW_DEFAULT_FEATURES + SINGLE_LINE_CAMERA_FEATURES + [ProductFeatures.MOP_SPIN_MODULE]
PEARL_FEATURES = SINGLE_LINE_CAMERA_FEATURES + [ProductFeatures.CLEANMODE_MAXPLUS, ProductFeatures.MOP_SPIN_MODULE]
PEARL_PLUS_FEATURES = NEW_DEFAULT_FEATURES + RGB_CAMERA_FEATURES + [ProductFeatures.MOP_SPIN_MODULE]
ULTRON_FEATURES = NEW_DEFAULT_FEATURES + DUAL_LINE_CAMERA_FEATURES + [ProductFeatures.MOP_SHAKE_MODULE]
ULTRONSV_FEATURES = NEW_DEFAULT_FEATURES + RGB_CAMERA_FEATURES + [ProductFeatures.MOP_SHAKE_MODULE]
TANOSS_FEATURES = NEW_DEFAULT_FEATURES + [ProductFeatures.MOP_SHAKE_MODULE]
TOPAZSPOWER_FEATURES = NEW_DEFAULT_FEATURES + [ProductFeatures.MOP_SHAKE_MODULE]
TANOSS_FEATURES = [ProductFeatures.REMOTE_BACK, ProductFeatures.MOP_SHAKE_MODULE]
TOPAZSPOWER_FEATURES = [ProductFeatures.CLEANMODE_MAXPLUS, ProductFeatures.MOP_SHAKE_MODULE]

product_feature_map = {
PRODUCTS_WITHOUT_CUSTOM_CLEAN: set[RoborockProductNickname] = {
RoborockProductNickname.TANOS,
RoborockProductNickname.RUBYPLUS,
RoborockProductNickname.RUBYSC,
RoborockProductNickname.RUBYSE,
}
PRODUCTS_WITHOUT_DEFAULT_3D_MAP: set[RoborockProductNickname] = {
RoborockProductNickname.TANOS,
RoborockProductNickname.TANOSSPLUS,
RoborockProductNickname.TANOSE,
RoborockProductNickname.TANOSV,
RoborockProductNickname.RUBYPLUS,
RoborockProductNickname.RUBYSC,
RoborockProductNickname.RUBYSE,
}
PRODUCTS_WITHOUT_PURE_CLEAN_MOP: set[RoborockProductNickname] = {
RoborockProductNickname.TANOS,
RoborockProductNickname.TANOSE,
RoborockProductNickname.TANOSV,
RoborockProductNickname.TANOSSLITE,
RoborockProductNickname.TANOSSE,
RoborockProductNickname.TANOSSC,
RoborockProductNickname.ULTRONLITE,
RoborockProductNickname.ULTRONE,
RoborockProductNickname.RUBYPLUS,
RoborockProductNickname.RUBYSLITE,
RoborockProductNickname.RUBYSC,
RoborockProductNickname.RUBYSE,
}

# Base map containing the initial, unconditional features for each product.
_BASE_PRODUCT_FEATURE_MAP: dict[RoborockProductNickname, list[ProductFeatures]] = {
RoborockProductNickname.PEARL: PEARL_FEATURES,
RoborockProductNickname.PEARLS: PEARL_FEATURES,
RoborockProductNickname.PEARLPLUS: PEARL_PLUS_FEATURES,
Expand All @@ -139,7 +170,8 @@ class ProductFeatures(StrEnum):
RoborockProductNickname.PEARLSLITE: PEARL_FEATURES,
RoborockProductNickname.PEARLE: PEARL_FEATURES,
RoborockProductNickname.PEARLELITE: PEARL_FEATURES,
RoborockProductNickname.VIVIANC: PEARL_PLUS_FEATURES,
RoborockProductNickname.VIVIANC: [ProductFeatures.CLEANMODE_MAXPLUS, ProductFeatures.MOP_SPIN_MODULE]
+ SINGLE_LINE_CAMERA_FEATURES,
RoborockProductNickname.CORALPRO: PEARL_PLUS_FEATURES,
RoborockProductNickname.ULTRONLITE: SINGLE_LINE_CAMERA_FEATURES
+ [ProductFeatures.CLEANMODE_NONE_PURECLEANMOP_WITH_MAXPLUS, ProductFeatures.MOP_ELECTRONIC_MODULE],
Expand All @@ -150,7 +182,7 @@ class ProductFeatures(StrEnum):
],
RoborockProductNickname.ULTRONSPLUS: ULTRON_FEATURES,
RoborockProductNickname.VERDELITE: ULTRONSV_FEATURES,
RoborockProductNickname.TOPAZS: NEW_DEFAULT_FEATURES + [ProductFeatures.MOP_SHAKE_MODULE],
RoborockProductNickname.TOPAZS: [ProductFeatures.REMOTE_BACK, ProductFeatures.MOP_SHAKE_MODULE],
RoborockProductNickname.TOPAZSPLUS: NEW_DEFAULT_FEATURES
+ DUAL_LINE_CAMERA_FEATURES
+ [ProductFeatures.MOP_SHAKE_MODULE],
Expand All @@ -173,6 +205,16 @@ class ProductFeatures(StrEnum):
RoborockProductNickname.RUBYSLITE: [ProductFeatures.MOP_ELECTRONIC_MODULE],
}

product_feature_map: dict[RoborockProductNickname, list[ProductFeatures]] = {
product: (
features
+ ([ProductFeatures.DEFAULT_CLEANMODECUSTOM] if product not in PRODUCTS_WITHOUT_CUSTOM_CLEAN else [])
+ ([ProductFeatures.DEFAULT_MAP3D] if product not in PRODUCTS_WITHOUT_DEFAULT_3D_MAP else [])
+ ([ProductFeatures.CLEANMODE_PURECLEANMOP] if product not in PRODUCTS_WITHOUT_PURE_CLEAN_MOP else [])
)
for product, features in _BASE_PRODUCT_FEATURE_MAP.items()
}


@dataclass
class DeviceFeatures:
Expand Down Expand Up @@ -424,6 +466,9 @@ class DeviceFeatures:
metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE, ProductFeatures.MOP_SPIN_MODULE]}
)
is_mop_shake_module_supported: bool = field(metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE]})
is_customized_clean_supported: bool = field(
metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE, ProductFeatures.MOP_SPIN_MODULE]}
)

@classmethod
def from_feature_flags(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_supported_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_supported_features_qrevo_maxv():
model = "roborock.vacuum.a87"
product_nickname = SHORT_MODEL_TO_ENUM.get(model.split(".")[-1])
device_features = DeviceFeatures.from_feature_flags(
new_feature_info=2247397454282751,
new_feature_info_str="000A177F7EFEFFFF",
new_feature_info=4499197267967999,
new_feature_info_str="508A977F7EFEFFFF",
feature_info=[111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125],
product_nickname=product_nickname,
)
Expand Down