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
48 changes: 46 additions & 2 deletions roborock/data/v1/v1_clean_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,23 @@ class CleaningMode(StrEnum):

VACUUM = "vacuum"
VAC_AND_MOP = "vac_and_mop"
VAC_THEN_MOP = "vac_then_mop"
"""Vacuum first with the mop pads detached, then return for the pads and mop.

Uses the same motor settings as `VAC_AND_MOP`; the order is a separate
device setting (`seq_type`) that the app writes alongside them. Some firmware
clears the order when a job ends, so the mode can read as `VAC_AND_MOP` again
after a run.
"""
MOP = "mop"
CUSTOM = "custom"
SMART_MODE = "smart_mode"


# `seq_type` value for "vacuum first, then mop"; 0 means both in one pass.
SEQ_TYPE_CLEAN_THEN_MOP = 1


_WATER_SLIDE_MODES: tuple[WaterModes, ...] = (
WaterModes.OFF,
WaterModes.PURE_WATER_FLOW_START,
Expand Down Expand Up @@ -241,6 +253,8 @@ def get_cleaning_mode_options(features: DeviceFeatures) -> list[CleaningMode]:

supported_water_modes = get_water_modes(features)
options = [CleaningMode.VACUUM, CleaningMode.VAC_AND_MOP]
if features.is_clean_then_mop_mode_supported:
options.append(CleaningMode.VAC_THEN_MOP)
if features.is_pure_clean_mop_supported:
options.append(CleaningMode.MOP)
if features.is_customized_clean_supported and WaterModes.CUSTOMIZED in supported_water_modes:
Expand Down Expand Up @@ -275,7 +289,7 @@ def _get_clean_motor_mode_params(
"""Return (fan_power, water_box_mode, mop_mode) enums for the high-level mode."""
if mode == CleaningMode.VACUUM:
return (VacuumModes.BALANCED, WaterModes.OFF, CleanRoutes.STANDARD)
if mode == CleaningMode.VAC_AND_MOP:
if mode in (CleaningMode.VAC_AND_MOP, CleaningMode.VAC_THEN_MOP):
return (VacuumModes.BALANCED, _get_default_mopping_water_mode(features), CleanRoutes.STANDARD)
if mode == CleaningMode.MOP:
return (
Expand Down Expand Up @@ -312,6 +326,28 @@ def get_cleaning_mode_parameters(cleaning_mode: CleaningMode, features: DeviceFe
return [params]


def get_clean_sequence_parameters(cleaning_mode: CleaningMode, features: DeviceFeatures) -> dict[str, int]:
"""Get the `app_set_clean_sequence_type` payload for a high-level cleaning mode.

The request carries the mode's motor settings (the same values as
`get_cleaning_mode_parameters`) together with the cleaning order, which is
enabled for `CleaningMode.VAC_THEN_MOP` and cleared for the other modes. The
app adds `repeat: 1` when enabling it on devices with
`is_ctm_with_repeat_supported`. `CUSTOM` and `SMART_MODE` are rejected: their
motor codes are placeholders that this request is not known to accept.
"""
if not features.is_clean_then_mop_mode_supported:
raise RoborockUnsupportedFeature("Clean then mop is not supported")
if cleaning_mode in (CleaningMode.CUSTOM, CleaningMode.SMART_MODE):
raise RoborockUnsupportedFeature(f"Cleaning mode {cleaning_mode.value!r} cannot set the cleaning order")
motor_params = get_cleaning_mode_parameters(cleaning_mode, features)[0]
enabled = cleaning_mode == CleaningMode.VAC_THEN_MOP
params = {**motor_params, "type": SEQ_TYPE_CLEAN_THEN_MOP if enabled else 0}
if enabled and features.is_ctm_with_repeat_supported:
params["repeat"] = 1
return params


def _resolve_mode_code(value: int | ModeEnumT | None, mode_cls: type[ModeEnumT]) -> ModeEnumT | None:
"""Resolve a raw code or enum into a RoborockModeEnum."""
if value is None:
Expand Down Expand Up @@ -346,8 +382,14 @@ def get_current_cleaning_mode(
water_mode: int | WaterModes | None,
mop_mode: int | CleanRoutes | None,
features: DeviceFeatures,
seq_type: int | None = None,
) -> CleaningMode | None:
"""Classify the current high-level cleaning mode from individual mode codes."""
"""Classify the current high-level cleaning mode from individual mode codes.

`seq_type` is the device's cleaning order (`get_status`); when it is
`SEQ_TYPE_CLEAN_THEN_MOP` on a device that supports it, vacuum-and-mop
settings are reported as `CleaningMode.VAC_THEN_MOP`.
"""
if not features.is_support_water_mode:
return None
clean_mode_enum = _resolve_clean_mode(clean_mode, features)
Expand All @@ -368,6 +410,8 @@ def get_current_cleaning_mode(
pass
if water_mode_enum == WaterModes.OFF:
return CleaningMode.VACUUM
if features.is_clean_then_mop_mode_supported and seq_type == SEQ_TYPE_CLEAN_THEN_MOP:
return CleaningMode.VAC_THEN_MOP
return CleaningMode.VAC_AND_MOP


Expand Down
7 changes: 3 additions & 4 deletions roborock/data/v1/v1_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from roborock.roborock_message import RoborockDataProtocol

from ..containers import NamedRoomMapping, RoborockBase, RoborockBaseTimer, _attr_repr, field_metadata
from .v1_clean_modes import WashTowelModes
from .v1_clean_modes import SEQ_TYPE_CLEAN_THEN_MOP, WashTowelModes
from .v1_code_mappings import (
CleanFluidStatus,
ClearWaterBoxStatus,
Expand Down Expand Up @@ -172,6 +172,8 @@ class StatusV2(RoborockBase):
repeat: int | None = None
kct: int | None = None
subdivision_sets: int | None = None
seq_type: int | None = field(default=None, metadata={"feature": "is_clean_then_mop_mode_supported"})
"""Cleaning sequence of the current run; 1 means vacuum the room, then mop it."""

@property
def square_meter_clean_area(self) -> float | None:
Expand Down Expand Up @@ -528,9 +530,6 @@ class WashTowelMode(RoborockBase):
wash_mode: WashTowelModes | None = None


SEQ_TYPE_CLEAN_THEN_MOP = 1


@dataclass
class SegmentCleanMode(RoborockBase):
"""A single room's clean mode override, as reported by the device.
Expand Down
42 changes: 37 additions & 5 deletions roborock/devices/traits/v1/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
WaterModes,
get_clean_modes,
get_clean_routes,
get_clean_sequence_parameters,
get_cleaning_mode_options,
get_cleaning_mode_parameters,
get_current_cleaning_mode,
Expand Down Expand Up @@ -83,6 +84,7 @@ class StatusTrait(StatusV2, common.V1TraitMixin, TraitUpdateListener):
- Fan Speed
- Water Mode
- Mop Route
- Cleaning order (``seq_type``, reported as ``CleaningMode.VAC_THEN_MOP``)

You should use the _options version of the attribute to know which are
supported for your device (i.e. fan_speed_options)
Expand Down Expand Up @@ -184,6 +186,7 @@ def current_cleaning_mode(self) -> CleaningMode | None:
water_mode=self.water_box_mode,
mop_mode=self.mop_mode,
features=self._device_features_trait,
seq_type=self.seq_type,
)

@property
Expand All @@ -193,11 +196,40 @@ def current_cleaning_mode_name(self) -> str | None:
return cleaning_mode.value

async def set_cleaning_mode(self, cleaning_mode: str | CleaningMode) -> None:
"""Set the preferred high-level cleaning mode for the device."""
await self.rpc_channel.send_command(
RoborockCommand.SET_CLEAN_MOTOR_MODE,
params=get_cleaning_mode_parameters(resolve_cleaning_mode(cleaning_mode), self._device_features_trait),
)
"""Set the preferred high-level cleaning mode for the device.

On devices that support clean then mop, the cleaning order is part of the
mode. Like the app, a change that may touch the order is sent as a single
``app_set_clean_sequence_type`` request, which carries the motor settings
too: it enables the order for ``CleaningMode.VAC_THEN_MOP`` and clears it
for the other modes, unless the device already reports it off.
``CUSTOM`` and ``SMART_MODE`` only write the motor settings.
"""
mode = resolve_cleaning_mode(cleaning_mode)
if not self._sets_clean_sequence(mode):
motor_params = get_cleaning_mode_parameters(mode, self._device_features_trait)
await self.rpc_channel.send_command(RoborockCommand.SET_CLEAN_MOTOR_MODE, params=motor_params)
return
sequence_params = get_clean_sequence_parameters(mode, self._device_features_trait)
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params)
# The request sets all of these at once, so listeners must see them change together.
self.fan_power = sequence_params["fan_power"]
self.water_box_mode = sequence_params["water_box_mode"]
if "mop_mode" in sequence_params:
self.mop_mode = sequence_params["mop_mode"]
self.seq_type = sequence_params["type"]
self._notify_update()
Comment on lines +214 to +221

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Priority 2 (Data Lifecycle & State Management): Partial local state mutation before _notify_update()

Updating only self.seq_type and calling self._notify_update() while leaving self.fan_power, self.water_box_mode, and self.mop_mode at their pre-call values exposes an inconsistent current_cleaning_mode to update listeners until the next refresh():

  • Switching VAC_THEN_MOP (water_box_mode=235, seq_type=1) -> VACUUM (water_box_mode=200, seq_type=0): self.seq_type becomes 0 while water_box_mode stays 235, so listeners read current_cleaning_mode == CleaningMode.VAC_AND_MOP instead of VACUUM.
  • Switching VACUUM (water_box_mode=200, seq_type=0) -> VAC_THEN_MOP: self.seq_type becomes 1 while water_box_mode stays 200, so listeners read clean_then_mop is True while current_cleaning_mode is still CleaningMode.VACUUM.

Suggested fix: Update all written motor fields alongside seq_type before notifying listeners (matching the official app's sendCleanWaterMopModeRpc, which updates cleanThenMop, fanPower, waterBoxMode, and mopMode together):

motor = motor_params[0]
self.fan_power = motor["fan_power"]
self.water_box_mode = motor["water_box_mode"]
if "mop_mode" in motor:
    self.mop_mode = motor["mop_mode"]
# (and self.seq_type = sequence_params["type"] when APP_SET_CLEAN_SEQUENCE_TYPE is sent)
self._notify_update()


def _sets_clean_sequence(self, mode: CleaningMode) -> bool:
"""Whether switching to ``mode`` goes through the cleaning order request."""
if not self._device_features_trait.is_clean_then_mop_mode_supported:
return False
# Their placeholder codes are not known to be accepted by the sequence request,
# and they are reported ahead of the order, so the order can stay as it is.
if mode in (CleaningMode.CUSTOM, CleaningMode.SMART_MODE):
return False
# An order that has not been loaded yet (None) may be on, so only a known 0 is skipped.
return mode == CleaningMode.VAC_THEN_MOP or self.seq_type != 0

async def resolve_error(self, error_code: int | None = None) -> None:
"""Resolve an error, like tapping "Resolved" in the Roborock app.
Expand Down
1 change: 1 addition & 0 deletions roborock/roborock_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RoborockCommand(str, Enum):
APP_SET_CROSS_CARPET_CLEANING_STATUS = "app_set_cross_carpet_cleaning_status"
APP_SET_DOOR_SILL_BLOCKS = "app_set_door_sill_blocks"
APP_SET_DIRTY_REPLENISH_CLEAN_STATUS = "app_set_dirty_replenish_clean_status"
APP_SET_CLEAN_SEQUENCE_TYPE = "app_set_clean_sequence_type"
APP_SET_DRYER_SETTING = "app_set_dryer_setting"
APP_SET_DRYER_STATUS = "app_set_dryer_status"
APP_SET_DYNAMIC_CONFIG = "app_set_dynamic_config"
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/__snapshots__/test_v1_device.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@
})
# ---
# name: test_device_trait_command_parsing[status]
StatusTrait(adbumper_status=None, auto_dust_collection=None, avoid_count=None, back_type=None, battery=100, camera_status=None, charge_status=None, clean_area=91287500, clean_fluid_status=None, clean_percent=None, clean_time=5405, cleaning_mode_options=[<CleaningMode.VACUUM: 'vacuum'>, <CleaningMode.VAC_AND_MOP: 'vac_and_mop'>, <CleaningMode.MOP: 'mop'>, <CleaningMode.CUSTOM: 'custom'>], clear_water_box_status=None, collision_avoid_status=None, command=<RoborockCommand.GET_STATUS: 'get_status'>, common_status=None, converter=DefaultConverter, corner_clean_mode=None, current_cleaning_mode=<CleaningMode.CUSTOM: 'custom'>, current_cleaning_mode_name='custom', current_map=0, debug_mode=None, dirty_water_box_status=None, distance_off=0, dnd_enabled=1, dock_cool_fan_status=None, dock_error_status=None, dock_state=<RoborockDockState.full: 'full'>, dock_type=None, dry_status=None, dss=None, dust_bag_status=None, dust_collection_status=None, error_code=<RoborockErrorCode.none: 0>, error_code_name='none', fan_power=106, fan_speed_mapping={101: 'quiet', 102: 'balanced', 103: 'turbo', 104: 'max', 108: 'max_plus', 105: 'off', 106: 'custom'}, fan_speed_name='custom', fan_speed_options=[<VacuumModes.QUIET: 'quiet'>, <VacuumModes.BALANCED: 'balanced'>, <VacuumModes.TURBO: 'turbo'>, <VacuumModes.MAX: 'max'>, <VacuumModes.MAX_PLUS: 'max_plus'>, <VacuumModes.OFF: 'off'>, <VacuumModes.CUSTOMIZED: 'custom'>], has_am=None, hatch_door_status=None, home_sec_enable_password=None, home_sec_status=None, in_cleaning=<RoborockInCleaning.complete: 0>, in_fresh_state=1, in_returning=0, in_warmup=None, is_battery_charging=False, is_exploring=None, is_locating=0, kct=None, lab_status=1, last_clean_t=None, lock_status=0, map_present=1, map_status=3, mop_forbidden_enable=0, mop_mode=None, mop_route_mapping={300: 'standard', 301: 'deep', 302: 'custom'}, mop_route_name=None, mop_route_options=[<CleanRoutes.STANDARD: 'standard'>, <CleanRoutes.DEEP: 'deep'>, <CleanRoutes.CUSTOMIZED: 'custom'>], msg_seq=515, msg_ver=2, rdt=None, repeat=None, replenish_mode=None, rss=None, square_meter_clean_area=91.3, state=<RoborockStateCode.charging: 8>, state_name='charging', subdivision_sets=None, switch_map_mode=None, unsave_map_flag=0, unsave_map_reason=4, wash_phase=None, wash_ready=None, wash_status=None, water_box_carriage_status=0, water_box_filter_status=None, water_box_mode=204, water_box_status=0, water_mode_mapping={200: 'off', 201: 'mild', 202: 'standard', 203: 'intense', 207: 'custom_water_flow', 204: 'custom'}, water_mode_name='custom', water_mode_options=[<WaterModes.OFF: 'off'>, <WaterModes.MILD: 'mild'>, <WaterModes.STANDARD: 'standard'>, <WaterModes.INTENSE: 'intense'>, <WaterModes.CUSTOM: 'custom_water_flow'>, <WaterModes.CUSTOMIZED: 'custom'>], water_shortage_status=None)
StatusTrait(adbumper_status=None, auto_dust_collection=None, avoid_count=None, back_type=None, battery=100, camera_status=None, charge_status=None, clean_area=91287500, clean_fluid_status=None, clean_percent=None, clean_time=5405, cleaning_mode_options=[<CleaningMode.VACUUM: 'vacuum'>, <CleaningMode.VAC_AND_MOP: 'vac_and_mop'>, <CleaningMode.MOP: 'mop'>, <CleaningMode.CUSTOM: 'custom'>], clear_water_box_status=None, collision_avoid_status=None, command=<RoborockCommand.GET_STATUS: 'get_status'>, common_status=None, converter=DefaultConverter, corner_clean_mode=None, current_cleaning_mode=<CleaningMode.CUSTOM: 'custom'>, current_cleaning_mode_name='custom', current_map=0, debug_mode=None, dirty_water_box_status=None, distance_off=0, dnd_enabled=1, dock_cool_fan_status=None, dock_error_status=None, dock_state=<RoborockDockState.full: 'full'>, dock_type=None, dry_status=None, dss=None, dust_bag_status=None, dust_collection_status=None, error_code=<RoborockErrorCode.none: 0>, error_code_name='none', fan_power=106, fan_speed_mapping={101: 'quiet', 102: 'balanced', 103: 'turbo', 104: 'max', 108: 'max_plus', 105: 'off', 106: 'custom'}, fan_speed_name='custom', fan_speed_options=[<VacuumModes.QUIET: 'quiet'>, <VacuumModes.BALANCED: 'balanced'>, <VacuumModes.TURBO: 'turbo'>, <VacuumModes.MAX: 'max'>, <VacuumModes.MAX_PLUS: 'max_plus'>, <VacuumModes.OFF: 'off'>, <VacuumModes.CUSTOMIZED: 'custom'>], has_am=None, hatch_door_status=None, home_sec_enable_password=None, home_sec_status=None, in_cleaning=<RoborockInCleaning.complete: 0>, in_fresh_state=1, in_returning=0, in_warmup=None, is_battery_charging=False, is_exploring=None, is_locating=0, kct=None, lab_status=1, last_clean_t=None, lock_status=0, map_present=1, map_status=3, mop_forbidden_enable=0, mop_mode=None, mop_route_mapping={300: 'standard', 301: 'deep', 302: 'custom'}, mop_route_name=None, mop_route_options=[<CleanRoutes.STANDARD: 'standard'>, <CleanRoutes.DEEP: 'deep'>, <CleanRoutes.CUSTOMIZED: 'custom'>], msg_seq=515, msg_ver=2, rdt=None, repeat=None, replenish_mode=None, rss=None, seq_type=None, square_meter_clean_area=91.3, state=<RoborockStateCode.charging: 8>, state_name='charging', subdivision_sets=None, switch_map_mode=None, unsave_map_flag=0, unsave_map_reason=4, wash_phase=None, wash_ready=None, wash_status=None, water_box_carriage_status=0, water_box_filter_status=None, water_box_mode=204, water_box_status=0, water_mode_mapping={200: 'off', 201: 'mild', 202: 'standard', 203: 'intense', 207: 'custom_water_flow', 204: 'custom'}, water_mode_name='custom', water_mode_options=[<WaterModes.OFF: 'off'>, <WaterModes.MILD: 'mild'>, <WaterModes.STANDARD: 'standard'>, <WaterModes.INTENSE: 'intense'>, <WaterModes.CUSTOM: 'custom_water_flow'>, <WaterModes.CUSTOMIZED: 'custom'>], water_shortage_status=None)
# ---
# name: test_device_trait_command_parsing[status].1
dict({
Expand Down
Loading