Skip to content

feat(v1): add CleaningMode.VAC_THEN_MOP - #1024

Open
paulleonartcalvo wants to merge 5 commits into
Python-roborock:mainfrom
paulleonartcalvo:feat/vac-then-mop-cleaning-mode
Open

paulleonartcalvo wants to merge 5 commits into
Python-roborock:mainfrom
paulleonartcalvo:feat/vac-then-mop-cleaning-mode

Conversation

@paulleonartcalvo

Copy link
Copy Markdown

Builds on #959 and implements the direction @allenporter suggested in this review comment: fold "clean then mop" into CleaningMode as a fourth mode, so consumers like Home Assistant get it through the existing cleaning mode select instead of a separate control. Closes #914.

The first three commits are @klowdo's from #959, rebased onto main unchanged. The last commit adds the mode on top. Happy to fold this into #959 instead if that is easier.

Changes

  • CleaningMode.VAC_THEN_MOP ("vac_then_mop"), offered in get_cleaning_mode_options() when is_clean_then_mop_mode_supported.
  • get_current_cleaning_mode() takes an optional seq_type and reports VAC_THEN_MOP for vacuum-and-mop settings with seq_type == 1; StatusTrait.current_cleaning_mode passes it through.
  • StatusTrait.set_cleaning_mode():
    • VAC_THEN_MOP: writes the vacuum-and-mop motor settings with set_clean_motor_mode, then app_set_clean_sequence_type with type: 1 and the same motor values (repeat: 1 when is_ctm_with_repeat_supported).
    • Any other mode while the sequence is on: sends type: 0 after the motor write, like the app. Nothing extra is sent when it is already off or unsupported.
  • clean_then_mop returns None on devices without the feature (point 3 of the review).
  • Removed the separate set_clean_then_mop() setter from feat(v1): expose clean-then-mop status from the device #959, since the mode now covers it and a standalone setter can produce the conflicting type: 1 with water_box_mode: 200 case from the review. Easy to restore if you would rather keep it.
  • SEQ_TYPE_CLEAN_THEN_MOP now lives in v1_clean_modes and is shared with the per-room CustomizeCleanModeTrait (feat(v1): expose per-room clean-then-mop via customize clean mode #984).

Device testing

Qrevo Edge 3 Pro (roborock.vacuum.a296, water slide, isCleanThenMopModeSupported and isCtmWithRepeatSupported both true):

  • Payload the official app sends when picking "Vacuum then mop": app_set_clean_sequence_type {"type": 1, "water_box_mode": 248, "mop_mode": 300, "fan_power": 102, "repeat": 1}. The robot answered ok.
  • With that set, a kitchen segment clean detached the mop pads for the vacuum pass, returned to the dock to reattach them, then went back out to mop.
  • Not yet verified on this model: reading seq_type back from get_status (verified on the Saros 20 in feat(v1): expose clean-then-mop status from the device #959).

uv run pytest (2301 passed) and uv run pre-commit run --all-files pass.

🤖 Generated with Claude Code

@Lash-L Lash-L added Feature New feature V1 V1 platform labels Nov 15, 2026
@lacroixdavid1

Copy link
Copy Markdown
Contributor

Device data from another model, in case it helps here: Qrevo S Pro (roborock.vacuum.a326, firmware 02.49.24, isCleanThenMopModeSupported and isCtmWithRepeatSupported both true). Measured on 2026-10-19 from Home Assistant (python-roborock 7.4.2 at the time), sending the raw command through vacuum.send_command.

Read-back of seq_type, which was still open for the a296 above

  • At the dock get_status reported seq_type: 0, with fan_power 104, water_box_mode 203, mop_mode 300.
  • app_set_clean_sequence_type with {"type": 1, "fan_power": 104, "water_box_mode": 203, "mop_mode": 300, "repeat": 1} returned ["ok"], and get_status then read seq_type: 1.

One job, vacuum then mop

A one-room segment clean started right after from Home Assistant ran as:

Elapsed State cleaning_info
0:00 18 segment cleaning fan_power 104, water_box_status 200 (no water)
5:35 26 going to wash the mop, 22 emptying the bin, 23 washing the mop
9:17 18 segment cleaning fan_power 105 (no suction), water_box_status 203
15:00 6 returning home

The top-level fan_power / water_box_mode / mop_mode stayed 104 / 203 / 300 the whole time; only cleaning_info shows which pass is running. Only the ordinary state codes, none of the 63xx ones. The job left a single clean record (complete 1, finish_reason 56).

The setting did not outlive the job

seq_type stayed 1 during the run. The first status while returning home read seq_type: 0, with nothing sent from Home Assistant in between. So on this model and firmware the robot clears it itself when the job ends. Two things follow for this PR:

  • current_cleaning_mode will read vac_and_mop again after each job, so a consumer has to select vac_then_mop before every run. In Home Assistant the select would flip back by itself.
  • The clean_then_mop docstring says the value is persisted on the device. That matches the idle Saros 20 test in feat(v1): expose clean-then-mop status from the device #959, but not this model once a job has run.

This is one run on one device, so take it as a data point, not a rule. I can repeat it on current firmware, or run a specific sequence, if that helps.

Done with AI assistance.


Generated by Claude Code

@Lash-L Lash-L left a comment

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.

Automated code review by Gemini 4 Neon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).

Summary by Architectural Layer

  • Priority 1 — Public Trait APIs & Consumer Contracts: Clean, consumer-agnostic design. Folding clean-then-mop into CleaningMode.VAC_THEN_MOP, gating cleaning_mode_options and clean_then_mop on is_clean_then_mop_mode_supported, and sharing SEQ_TYPE_CLEAN_THEN_MOP in v1_clean_modes all align with AGENTS.md and StatusV2 conventions.
  • Priority 2 — Data Lifecycle & State Management: 1 finding — StatusTrait.set_cleaning_mode() updates only self.seq_type before calling self._notify_update(), leaving fan_power, water_box_mode, and mop_mode stale and exposing a torn current_cleaning_mode snapshot to listeners until the next refresh() (see inline comment).
  • Priority 3 — Wire Protocols & App Verification (RR_API):
    • Verified app_set_clean_sequence_type payload schema (type, fan_power, water_box_mode, mop_mode, plus repeat: 1 when type == 1 and isCtmWithRepeatSupported()), seq_type == 1 status decoding, and isCleanThenMopSupported (CleanThenMopMode) / isCtmWithRepeatSupported (CtmWithRepeat) feature flags against the official Roborock app bundles (com.roborock.tanos & Qrevo Edge 3 Pro).
    • 1 protocol improvement: In the official app (sendCleanWaterMopModeRpc), changing cleanThenMopMode sends only app_set_clean_sequence_type (not set_clean_motor_mode followed by app_set_clean_sequence_type), because app_set_clean_sequence_type carries the motor parameters itself (see inline comment).
    • Note on @lacroixdavid1's real-device observation: on at least some firmware (a326), the robot automatically resets seq_type back to 0 at the end of a cleaning run, so the clean_then_mop docstring's "persisted on the device" phrasing is worth keeping in mind for downstream consumers.
  • Tests & CI: Unit tests are properly colocated in tests/devices/traits/v1/test_status.py using @pytest.mark.parametrize, and all CI checks pass. Adding an assertion on status_trait.current_cleaning_mode after set_cleaning_mode() would cover the state-consistency finding above.

Comment on lines +187 to +189
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params)
self.seq_type = sequence_params["type"]
self._notify_update()

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()

Comment thread roborock/devices/traits/v1/status.py Outdated
Comment on lines +181 to +187
await self.rpc_channel.send_command(RoborockCommand.SET_CLEAN_MOTOR_MODE, params=motor_params)
if not self._device_features_trait.is_clean_then_mop_mode_supported:
return
if mode != CleaningMode.VAC_THEN_MOP and not self.clean_then_mop:
return
sequence_params = get_clean_sequence_parameters(mode, motor_params[0], self._device_features_trait)
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params)

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 3 (Wire Protocol): app_set_clean_sequence_type replaces set_clean_motor_mode in the official app

In the official Roborock app (sendCleanWaterMopModeRpc), when cleanThenMopMode changes, the app sends only app_set_clean_sequence_type (which already carries fan_power, water_box_mode, mop_mode, and optional repeat: 1) and skips set_clean_motor_mode. It only sends set_clean_motor_mode when the clean-then-mop state is unchanged.

Sending both RPCs adds an extra round-trip and introduces a partial-failure window if SET_CLEAN_MOTOR_MODE succeeds and APP_SET_CLEAN_SEQUENCE_TYPE fails or times out. Consider branching so only one command is sent:

mode = resolve_cleaning_mode(cleaning_mode)
motor_params = get_cleaning_mode_parameters(mode, self._device_features_trait)
update_sequence = self._device_features_trait.is_clean_then_mop_mode_supported and (
    mode == CleaningMode.VAC_THEN_MOP or bool(self.clean_then_mop)
)
if update_sequence:
    sequence_params = get_clean_sequence_parameters(mode, motor_params[0], self._device_features_trait)
    await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params)
    self.seq_type = sequence_params["type"]
else:
    await self.rpc_channel.send_command(RoborockCommand.SET_CLEAN_MOTOR_MODE, params=motor_params)

@Lash-L Lash-L added the /review run Code review skill (/review) has been run label Nov 21, 2026
@matte-oss

Copy link
Copy Markdown

Hi, and thanks for working on this. I own a Roborock Qrevo Edge 2 and was hitting the same problem in Home Assistant: the cleaning mode shows as unknown when the app is set to "Vacuum then mop". I tested what this PR implements on my robot, including the seq_type read-back that the description lists as not yet verified.

Device: Roborock Qrevo Edge 2 (roborock.vacuum.a298), V1 protocol over the local L01 transport, water slide. is_clean_then_mop_mode_supported evaluates to True from the device's newFeatureSet. I did not run the code from this PR. I only sent raw commands to the robot, through Home Assistant's vacuum.send_command, and decoded a capture of the official app.

What the official app sends
I captured the app's local traffic (L01, TCP 58867) and decrypted it. Choosing "Vacuum then mop" produced:

app_set_clean_sequence_type
{"mop_mode": 300, "water_box_mode": 240, "type": 1, "repeat": 1, "fan_power": 103}

This is the same shape as the payload in the PR description. The app also sent set_clean_motor_mode with the plain fan/water/mop values.

Read-back of seq_type (verified)
get_status returns seq_type: 1 while the app is set to "Vacuum then mop", and seq_type: 0 while it is set to "Vacuum and mop".

With the robot docked, I sent the command above by hand with the same fan, water and mop values:

  • type: 0: the robot answered ok, and the next get_status returned seq_type: 0.
  • type: 1: the robot answered ok, and the next get_status returned seq_type: 1.

Things that do not work
I also tried the following, and seq_type stayed at 0 each time, even though the robot answered ok:

  • set_clean_motor_mode with an extra seq_type key;
  • app_segment_clean with an extra seq_type key.

So app_set_clean_sequence_type is needed, as implemented here. Writing set_clean_motor_mode first and then the sequence type, like the app does, looks right.

Not tested: a full cleaning run with type: 1.

I can attach the decoded frames (with my device key and IDs removed) if that helps.

@southseaboy

Copy link
Copy Markdown

Confirmed on a Qrevo Edge 2 Flow (roborock.vacuum.a328, firmware 02.29.06, V1 protocol), sending the raw command through Home Assistant's vacuum.send_command while the robot was docked and idle:

  • app_set_clean_sequence_type with {"type": 1, "fan_power": 102, "water_box_mode": 235, "mop_mode": 300, "repeat": 1} — the Roborock app then showed "Vacuum then mop".
  • The same command with {"type": 0, "fan_power": 102, "water_box_mode": 235, "mop_mode": 300} — the app returned to "Vacuum and mop".

The diagnostics report is_clean_then_mop_mode_supported and is_ctm_with_repeat_supported as true.

@allenporter allenporter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Marking as requesting changes given the feedback below.

@allenporter allenporter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for following up on the #959 direction and to everyone who tested on real hardware — folding this into CleaningMode.VAC_THEN_MOP is much cleaner for downstream consumers.

In addition to the partial state-update issue already noted in this comment, a few other items need changes before merging (details inline):

  1. Drop the redundant StatusTrait.clean_then_mop public property now that CleaningMode.VAC_THEN_MOP models it.
  2. Handle self.seq_type is None (unloaded status) and CleaningMode.CUSTOM / CleaningMode.SMART_MODE safely in StatusTrait.set_cleaning_mode().
  3. Tighten get_clean_sequence_parameters() so it derives motor params from (cleaning_mode, features) (or keep it private) instead of exporting a loose-dict helper.
  4. Rebase onto main to resolve the merge conflict with #1067.

Comment thread roborock/devices/traits/v1/status.py Outdated
Comment on lines +137 to +154
@property
def clean_then_mop(self) -> bool | None:
"""Whether each room is vacuumed fully before it is mopped.

Reported by the device as ``seq_type`` and persisted on the device: it
tracks the "vacuum then mop" choice in the vendor app, also while docked.

The device stores it separately from ``fan_power``, ``water_box_mode``
and ``mop_mode``, but the app presents it as a fourth cleaning mode, so
``current_cleaning_mode`` reports ``CleaningMode.VAC_THEN_MOP`` when it
is set with vacuum-and-mop settings, and ``set_cleaning_mode`` writes it.

``None`` means the device does not support the feature or has not
reported it.
"""
if not self._device_features_trait.is_clean_then_mop_mode_supported or self.seq_type is None:
return None
return self.seq_type == SEQ_TYPE_CLEAN_THEN_MOP

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that clean-then-mop is folded into CleaningMode.VAC_THEN_MOP and set_clean_then_mop() has been removed, let's drop StatusTrait.clean_then_mop rather than adding a second public property for the same state:

  • It can disagree with current_cleaning_mode (e.g., returning True while current_cleaning_mode is VACUUM, MOP, CUSTOM, or SMART_MODE).
  • Consumers already have current_cleaning_mode == CleaningMode.VAC_THEN_MOP and CleaningMode.VAC_THEN_MOP in cleaning_mode_options.

Comment thread roborock/devices/traits/v1/status.py Outdated
Comment on lines +184 to +187
if mode != CleaningMode.VAC_THEN_MOP and not self.clean_then_mop:
return
sequence_params = get_clean_sequence_parameters(mode, motor_params[0], self._device_features_trait)
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two additional edge cases here beyond the state-update comment above:

  1. Unloaded self.seq_type is None: not self.clean_then_mop treats seq_type is None (before refresh()) the same as seq_type == 0, so calling set_cleaning_mode(CleaningMode.VAC_AND_MOP) on an unrefreshed trait skips sending type: 0 even if the robot currently has seq_type == 1. Prefer skipping only when self.seq_type == 0.
  2. CUSTOM / SMART_MODE sentinel codes: On non-water-slide devices with is_clean_then_mop_mode_supported=True (like a326), CleaningMode.CUSTOM and CleaningMode.SMART_MODE are valid options. Switching to them while seq_type == 1 currently sends sentinel codes (106/204/302 or 110/209/306) to app_set_clean_sequence_type, which is untested and likely rejected by firmware (as in CustomizeCleanModeTrait). Since get_current_cleaning_mode() already prioritizes CUSTOM/SMART_MODE above seq_type, either verify firmware accepts them or skip APP_SET_CLEAN_SEQUENCE_TYPE for those two modes (with test coverage).

Comment thread roborock/data/v1/v1_clean_modes.py Outdated
Comment on lines +327 to +345
def get_clean_sequence_parameters(
cleaning_mode: CleaningMode,
motor_params: dict[str, int],
features: DeviceFeatures,
) -> dict[str, int]:
"""Get the `app_set_clean_sequence_type` payload for a high-level cleaning mode.

The firmware requires the motor settings (`fan_power`, `water_box_mode` and
`mop_mode`) in the request, so `motor_params` should be the values just sent
with `set_clean_motor_mode`. The app adds `repeat: 1` when enabling the
sequence on devices with `is_ctm_with_repeat_supported`.
"""
if not features.is_clean_then_mop_mode_supported:
raise RoborockUnsupportedFeature("Clean then mop is not supported")
enabled = cleaning_mode == CleaningMode.VAC_THEN_MOP
params = {"type": SEQ_TYPE_CLEAN_THEN_MOP if enabled else 0, **motor_params}
if enabled and features.is_ctm_with_repeat_supported:
params["repeat"] = 1
return params

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because v1_clean_modes is star-exported at the top-level roborock namespace, get_clean_sequence_parameters becomes public API. Taking a raw motor_params: dict[str, int] alongside cleaning_mode allows contradictory (cleaning_mode, motor_params) pairs (e.g., VAC_THEN_MOP with water_box_mode: 200), and {"type": ..., **motor_params} lets a "type" key in motor_params overwrite the computed sequence type.

Could we match get_cleaning_mode_parameters(cleaning_mode, features) and derive the motor params internally (or make this private _get_clean_sequence_parameters if only StatusTrait calls it)?

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."""
    if not features.is_clean_then_mop_mode_supported:
        raise RoborockUnsupportedFeature("Clean then mop is not supported")
    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

@paulleonartcalvo

Copy link
Copy Markdown
Author

Will address tomorrow and fix up the pr!

klowdo and others added 5 commits December 2, 2026 21:09
The device reports seq_type in its get_status payload, but StatusV2 did not
model it, so RoborockBase.from_dict discarded it along with every other
unmatched key. The vendor app reads the same field off the same payload to
derive its "clean then mop" state.

Add seq_type to StatusV2 and a clean_then_mop property on StatusTrait that
reports whether the current run vacuums each room fully before mopping it.
It describes the run in progress rather than a persisted setting, and the
device offers no setter, so it is read only here; the value travels outbound
as a parameter of the cleaning command instead.

Gated for reporting on is_clean_then_mop_mode_supported.

Verified against a Roborock Saros 20 (roborock.vacuum.a288).
Model the app's "Vacuum then mop" choice as a fourth high-level cleaning
mode, as suggested in review of Python-roborock#959, so consumers such as Home Assistant
get it through cleaning_mode_options / current_cleaning_mode /
set_cleaning_mode without orchestrating a separate control.

- Offer VAC_THEN_MOP when is_clean_then_mop_mode_supported.
- Report it when vacuum-and-mop settings run with seq_type 1.
- set_cleaning_mode writes the vacuum-and-mop motor settings, then
  app_set_clean_sequence_type with type 1 (repeat 1 when
  is_ctm_with_repeat_supported); switching to another mode while it is
  enabled sends type 0, like the app.
- clean_then_mop returns None on devices without the feature.
- Replace the separate set_clean_then_mop setter with the mode, and share
  SEQ_TYPE_CLEAN_THEN_MOP with the per-room customize clean mode trait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address review of the clean-then-mop cleaning mode:

- set_cleaning_mode sends only app_set_clean_sequence_type when the
  cleaning order may change, like the app; it carries the motor settings,
  so there is no partial-failure window between two requests.
- Update fan_power, water_box_mode, mop_mode and seq_type together before
  notifying, so listeners never see a torn current_cleaning_mode.
- Clear the order when seq_type has not been loaded yet (None); skip it
  only when the device reports 0.
- CUSTOM and SMART_MODE only write the motor settings and never send
  their placeholder codes in a sequence request.
- get_clean_sequence_parameters derives the motor settings from
  (cleaning_mode, features) and rejects CUSTOM / SMART_MODE.
- Drop StatusTrait.clean_then_mop; current_cleaning_mode covers it.
- Note that some firmware clears the order when a job ends.
- Restore the RoborockException import lost while rebasing onto main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paulleonartcalvo
paulleonartcalvo force-pushed the feat/vac-then-mop-cleaning-mode branch from 046d7f6 to f636608 Compare December 3, 2026 02:13
@paulleonartcalvo

Copy link
Copy Markdown
Author

@allenporter @Lash-L addressed all the review comments and rebased onto main. Should be good for another look whenever you get a chance, thanks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature /review run Code review skill (/review) has been run V1 V1 platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the "Clean then mop" cleaning mode (feature bit 93, is_clean_then_mop_mode_supported)

7 participants