Repository navigation
feat(v1): generalize segment clean mode updates and preserve existing settings - #1050
Conversation
d8bcbb9 to
389b0a3
Compare
db4a64e to
58f99e7
Compare
Lash-L
left a comment
There was a problem hiding this comment.
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 onset_segment_clean_mode, backwards-compatibleset_clean_then_mopwrapper, concrete types on public boundaries, and_raw_by_segmentproperly annotated asdict[int, dict[str, Any]]. One gap:repeatis not feature-gated onis_custom_clean_mode_count_supported(unlikeclean_then_mop/is_clean_then_mop_mode_supported), and"repeat": 1is 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-writeawait self.refresh()inside_write_locktoif self.modes is None:re-introduces silent clobbering of external edits (vendor app changes or multi-map floor switches) becauseset_customize_clean_modereplaces the entire segment table and this trait has no push updates (see inline comment). - Priority 3 — Wire Protocols, Codecs &
RR_APIVerification:- Verified against Roborock app bundles (
nonhermes/com.roborock.tanos,hermes/com.roborock.tanos,Saros 20,Saros 10R):set_customize_clean_modesends the full array of per-segment dicts (segment,fan_power,water_box_mode,mop_mode, plus optionalrepeat,seq_type,mop_type,mop_power). Preserving unmodeled per-model keys via_raw_by_segmentmatches firmware expectations.- Rejecting global sentinel codes (
106/110,204/209,302/306) is accurate and prevents invalid writes fromStatusTrait. seq_type(1= clean-then-mop,0= normal) is stripped/omitted whenisCleanThenMopSupported()is false, matching this PR'sis_clean_then_mop_mode_supportedgate.repeatis only attached whenNewFeatureStrBit.CustomCleanModeCount(bit 51 =DeviceFeatures.is_custom_clean_mode_count_supported) is supported — e.g.Falseon S7 MaxV (a27),Trueon Q Revo / Saros 10R / Qrevo 2 Pro.
- Verified against Roborock app bundles (
- 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, updatetest_set_segment_clean_mode_skips_pre_refresh_when_already_loadedandtest_set_segment_clean_mode_on_device_without_clean_then_mopaccordingly.
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() |
There was a problem hiding this comment.
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:
- 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. - On multi-floor vacuums, switching maps leaves
self.modesnon-Nonewith 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()There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
58f99e7 to
0d4824a
Compare
Lash-L
left a comment
There was a problem hiding this comment.
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
- Restore the unconditional pre-write
refresh(): Fixed.customize_clean_mode.py:175-178now callsawait self.refresh()inside_write_lockbefore every merge, the same as #984 onmain. Theskips_pre_refresh_when_already_loadedtest was removed, and every remaining write test expects GET, SET, GET. - Gate
repeatonis_custom_clean_mode_count_supported: Fixed.- An explicit
repeaton an unsupported device raisesRoborockUnsupportedFeaturebefore any RPC (:165-169). - The generated
"repeat"key is left out of the update on unsupported devices (:196-200). Anyrepeatthe 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_unsupportedand the updated S7 MaxV test. - RR_API agrees:
nonhermes/com.roborock.tanos/index.android.bundle:1843sets the room'scleanCountto1only whenCustomCleanModeCountis supported and to-1otherwise (canBlockCleanCount,setAllCleanMopMode). Line 408 maps that flag to bit 51.
- An explicit
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 nomop_modeis now rejected before the write. That is correct: #984 found that firmware rejects requests withoutmop_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 saysrepeat"defaults to1" for new rooms with no condition. That now only happens whenis_custom_clean_mode_count_supportedis true. Suggested wording: "...andrepeatdefaults to1on devices that support per-room repeat counts (omitting it there resets it to1on firmware)." - Nit, stale PR description: the body still says the trait "Lazily refreshes before writing only when
self.modes is None", and thatrepeatdefaults to1with no condition. Both are no longer true after0d4824a. 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
CUSTOMIZEDandSMART_MODEenum members that this PR's sentinel rejection depends on. The two complement each other. - Local results at
0d4824a:pytest: 2837 passed, 46 xfailed. Thetest_customize_clean_mode.pysuite: 41 passed.ruff checkandruff 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
left a comment
There was a problem hiding this comment.
tested the settings on my vac and seems to be working correctly.
Summary
Follow-up to #984 for
CustomizeCleanModeTrait:set_segment_clean_modeand preserve existing settings on partial updates: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.repeat=2to1or requiring callers to re-supply unchanged modes). When adding an override for a room without an existing entry,fan_power,water_box_mode, andmop_modeare required andrepeatdefaults to1.set_clean_then_mopas a backwards-compatible wrapper with optional mode/repeat arguments.self.modes is None, relying on the post-writerefresh()once loaded.repeatvalues:CUSTOMIZED106/204/302andSMART_MODE110/209/306) andrepeat < 1(or empty updates) withValueErrorbefore sending an RPC.