Skip to content

feat(v1): generalize segment clean mode updates and preserve existing settings - #1050

Merged
Lash-L merged 1 commit into
Python-roborock:mainfrom
allenporter:fix/customize-clean-mode-followup
Nov 25, 2026
Merged

Lash-L merged 1 commit into
Python-roborock:mainfrom
allenporter:fix/customize-clean-mode-followup

Conversation

@allenporter

@allenporter allenporter commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #984 for CustomizeCleanModeTrait:

  • Expose set_segment_clean_mode and preserve existing settings on partial updates:
    • Adds CustomizeCleanModeTrait.set_segment_clean_mode(segment, *, fan_power=None, water_box_mode=None, mop_mode=None, repeat=None, clean_then_mop=None) so V1 devices that support per-room custom modes (is_customized_clean_supported) without clean-then-mop (is_clean_then_mop_mode_supported=False, e.g. S7 MaxV, S8, Q Revo) can also configure per-room suction, water flow, route, and repeat count.
    • When updating a segment that already has an override on the device, any omitted fields preserve that room's existing values (avoiding resetting repeat=2 to 1 or requiring callers to re-supply unchanged modes). When adding an override for a room without an existing entry, fan_power, water_box_mode, and mop_mode are required and repeat defaults to 1.
    • Keeps set_clean_then_mop as a backwards-compatible wrapper with optional mode/repeat arguments.
    • Lazily refreshes before writing only when self.modes is None, relying on the post-write refresh() once loaded.
  • Reject global sentinel mode codes and invalid repeat values:
    • Rejects global status sentinel codes (CUSTOMIZED 106/204/302 and SMART_MODE 110/209/306) and repeat < 1 (or empty updates) with ValueError before sending an RPC.
  • Documentation:
    • Clarifies that the robot only applies the stored per-room table when its global cleaning mode is set to custom, and tightens comments/docstrings.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 23:23

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@allenporter
allenporter force-pushed the fix/customize-clean-mode-followup branch 4 times, most recently from d8bcbb9 to 389b0a3 Compare November 14, 2026 23:37
@allenporter
allenporter requested a review from Lash-L November 14, 2026 23:59
@allenporter
allenporter marked this pull request as draft November 15, 2026 04:43
@Lash-L Lash-L added Feature New feature V1 V1 platform labels Nov 15, 2026
@allenporter
allenporter force-pushed the fix/customize-clean-mode-followup branch 3 times, most recently from db4a64e to 58f99e7 Compare November 16, 2026 05:09
@allenporter
allenporter marked this pull request as ready for review November 22, 2026 01:42

@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 (roborock/devices/traits/v1/customize_clean_mode.py): Clean public signature on set_segment_clean_mode, backwards-compatible set_clean_then_mop wrapper, concrete types on public boundaries, and _raw_by_segment properly annotated as dict[int, dict[str, Any]]. One gap: repeat is not feature-gated on is_custom_clean_mode_count_supported (unlike clean_then_mop / is_clean_then_mop_mode_supported), and "repeat": 1 is emitted even on devices that do not support per-room repeat counts (see inline comment).
  • Priority 2 — Lifecycle, State & Concurrency (roborock/devices/traits/v1/customize_clean_mode.py): One regression: changing the pre-write await self.refresh() inside _write_lock to if self.modes is None: re-introduces silent clobbering of external edits (vendor app changes or multi-map floor switches) because set_customize_clean_mode replaces the entire segment table and this trait has no push updates (see inline comment).
  • Priority 3 — Wire Protocols, Codecs & RR_API Verification:
    • Verified against Roborock app bundles (nonhermes/com.roborock.tanos, hermes/com.roborock.tanos, Saros 20, Saros 10R):
      • set_customize_clean_mode sends the full array of per-segment dicts (segment, fan_power, water_box_mode, mop_mode, plus optional repeat, seq_type, mop_type, mop_power). Preserving unmodeled per-model keys via _raw_by_segment matches firmware expectations.
      • Rejecting global sentinel codes (106/110, 204/209, 302/306) is accurate and prevents invalid writes from StatusTrait.
      • seq_type (1 = clean-then-mop, 0 = normal) is stripped/omitted when isCleanThenMopSupported() is false, matching this PR's is_clean_then_mop_mode_supported gate.
      • repeat is only attached when NewFeatureStrBit.CustomCleanModeCount (bit 51 = DeviceFeatures.is_custom_clean_mode_count_supported) is supported — e.g. False on S7 MaxV (a27), True on Q Revo / Saros 10R / Qrevo 2 Pro.
  • Tests (tests/devices/traits/v1/test_customize_clean_mode.py): Well-colocated in the mirror path, parametrized, using real device fixtures and public-behavior assertions. If the two findings below are addressed, update test_set_segment_clean_mode_skips_pre_refresh_when_already_loaded and test_set_segment_clean_mode_on_device_without_clean_then_mop accordingly.

Verdict: Needs 2 targeted fixes before approval (restore unconditional pre-write refresh() to prevent silent table clobbering; gate repeat on is_custom_clean_mode_count_supported).

# Lazily load the existing table if the caller hasn't refreshed yet
# so a full-table SET doesn't wipe other rooms.
if self.modes is None:
await self.refresh()

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 — State / Stale-Cache Clobbering Regression

Skipping await self.refresh() when self.modes is not None regresses the safety invariant from #984. Because SET_CUSTOMIZE_CLEAN_MODE replaces the entire per-room table on V1 firmware and CustomizeCleanModeTrait has no push/event subscription:

  1. Any room edited, added, or reset in the Roborock mobile app (or another client) after the initial load will be silently reverted/wiped on the next set_segment_clean_mode() call.
  2. On multi-floor vacuums, switching maps leaves self.modes non-None with the previous floor's segment table, which would then be written onto the active floor.

Saving one get_customize_clean_mode RPC on an infrequent configuration write is not worth silent data loss. Please restore the unconditional pre-write refresh inside async with self._write_lock::

        async with self._write_lock:
            # Always refresh immediately before merging so a full-table SET
            # never clobbers external edits (e.g. from the vendor app or a map switch).
            await self.refresh()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Restored the unconditional pre-write await self.refresh() inside self._write_lock in 0d4824a3.

"fan_power": fan_code,
"water_box_mode": water_code,
"mop_mode": mop_code,
"repeat": repeat or (existing_mode.repeat if existing_mode else None) or 1,

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 1 / 3 — Missing is_custom_clean_mode_count_supported Feature Gate (RR_API)

In both legacy and modern Roborock app bundles, repeat is only added to set_customize_clean_mode entries when NewFeatureStrBit.CustomCleanModeCount (bit 51, already mapped to DeviceFeatures.is_custom_clean_mode_count_supported) is supported. Older is_customized_clean_supported devices like S7 MaxV (a27, the default test fixture here) have is_custom_clean_mode_count_supported=False.

Per AGENTS.md (Compound Capability & Feature Gating), explicit repeat writes should be gated just like clean_then_mop, and "repeat" should be omitted from new_entry when unsupported:

        if repeat is not None:
            if not self._device_features.is_custom_clean_mode_count_supported:
                raise RoborockUnsupportedFeature("Device does not support per-segment repeat count")
            if repeat < 1:
                raise ValueError(f"repeat must be >= 1, got {repeat}")

And when building updates:

                "repeat": (
                    (repeat or (existing_mode.repeat if existing_mode else None) or 1)
                    if self._device_features.is_custom_clean_mode_count_supported
                    else None
                ),

This preserves #984's real-device fix (always sending repeat when supported so firmware doesn't reset it to 1) while avoiding sending an unsupported repeat field on older firmware.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gated repeat on self._device_features.is_custom_clean_mode_count_supported (raising RoborockUnsupportedFeature when passed on unsupported devices and omitting "repeat" from updates when unsupported) and added test coverage in 0d4824a3.

@Lash-L Lash-L added the /review run Code review skill (/review) has been run label Nov 22, 2026
@allenporter
allenporter force-pushed the fix/customize-clean-mode-followup branch from 58f99e7 to 0d4824a Compare November 24, 2026 16:03
@allenporter
allenporter requested a review from Lash-L November 24, 2026 16:58

@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 Claude Opus 5.5 in Claude Code using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).

Follow-Up Review (0d4824a, delta from 58f99e7)

Verdict: Passes /review with nits.

The branch was rebased onto current main, so this compares the PR's own changes to customize_clean_mode.py and its tests at 58f99e7 with those at 0d4824a. It still merges cleanly into main, and it merges cleanly alongside #1064.

Earlier blocking findings

  1. Restore the unconditional pre-write refresh(): Fixed. customize_clean_mode.py:175-178 now calls await self.refresh() inside _write_lock before every merge, the same as #984 on main. The skips_pre_refresh_when_already_loaded test was removed, and every remaining write test expects GET, SET, GET.
  2. Gate repeat on is_custom_clean_mode_count_supported: Fixed.
    • An explicit repeat on an unsupported device raises RoborockUnsupportedFeature before any RPC (:165-169).
    • The generated "repeat" key is left out of the update on unsupported devices (:196-200). Any repeat the device already reported stays, because the update is laid over the room's raw dict.
    • On supported devices it still sends repeat or existing.repeat or 1, which keeps #984's real-device fix.
    • Covered by test_set_segment_clean_mode_repeat_unsupported and the updated S7 MaxV test.
    • RR_API agrees: nonhermes/com.roborock.tanos/index.android.bundle:1843 sets the room's cleanCount to 1 only when CustomCleanModeCount is supported and to -1 otherwise (canBlockCleanCount, setAllCleanMopMode). Line 408 maps that flag to bit 51.

The author's replies fixed both findings and disputed neither, so nothing was in contention.

New in this delta

  • The required-modes check (:180-189) now looks at the room's effective values (argument, else the existing value) instead of only checking whether an entry exists. A room that has an override but no mop_mode is now rejected before the write. That is correct: #984 found that firmware rejects requests without mop_mode. The parametrized test covers both the new-room and partial-entry cases.

Priority 1 — Public Trait APIs

  • No issues. set_clean_then_mop's mode arguments went from required to optional and the new ones are keyword-only, so existing callers keep working.

Priority 2 — Lifecycle & State

  • No issues. The read-merge-write is serialized and refreshed both before and after the write.

Priority 3 — Wire Protocol

  • No issues.

Tests & PR hygiene

  • Nit, stale docstring (customize_clean_mode.py:153-155): it still says repeat "defaults to 1" for new rooms with no condition. That now only happens when is_custom_clean_mode_count_supported is true. Suggested wording: "...and repeat defaults to 1 on devices that support per-room repeat counts (omitting it there resets it to 1 on firmware)."
  • Nit, stale PR description: the body still says the trait "Lazily refreshes before writing only when self.modes is None", and that repeat defaults to 1 with no condition. Both are no longer true after 0d4824a. Please update it before squash-merge so the release notes are accurate.
  • Overlap with #1064: the two PRs change different files. #1064 adds global fan, water and route setters that refuse changes in SmartPlan or custom mode. It still uses the CUSTOMIZED and SMART_MODE enum members that this PR's sentinel rejection depends on. The two complement each other.
  • Local results at 0d4824a:
    • pytest: 2837 passed, 46 xfailed. The test_customize_clean_mode.py suite: 41 passed.
    • ruff check and ruff format --check: clean.
    • CI: green on every job.

This is an automated review and can be incorrect, so please reply if any finding looks wrong.

@Lash-L Lash-L added the Passed /review Passed the /review skill check label Nov 25, 2026

@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.

tested the settings on my vac and seems to be working correctly.

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

Labels

Feature New feature Passed /review Passed the /review skill check /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.

3 participants