Skip to content

feat(v1): add CleanSequenceTrait for the room cleaning order - #1062

Open
cptntrps wants to merge 2 commits into
Python-roborock:mainfrom
cptntrps:feat/clean-sequence-trait
Open

cptntrps wants to merge 2 commits into
Python-roborock:mainfrom
cptntrps:feat/clean-sequence-trait

Conversation

@cptntrps

Copy link
Copy Markdown
Contributor

Summary

Adds CleanSequenceTrait (device.v1_properties.clean_sequence) for the order in which a device cleans rooms.

  • refresh() reads get_clean_sequence into CleanSequence.rooms (segment ids in cleaning order).
  • set_order(rooms) writes set_clean_sequence. It refuses an empty list or a repeated room before anything is sent.
  • Gated on is_order_clean_supported (robot feature 123), the same pattern as the other optional traits.

Tested on a Saros 10R (a144)

Step Result
get_clean_sequence [8, 3, 7, 10, 1, 9]
app_segment_clean of rooms 8 and 7 with that order, two runs the robot cleaned room 8 first both times
set_clean_sequence [7, 8, 3, 10, 1, 9], then the same clean the robot cleaned room 7 first
set_clean_sequence while the robot was returning to the dock -10007 invalid status; accepted again once docked

The device reports feature 123 in app_get_init_status, so is_order_clean_supported is True on it. SUPPORTED_FEATURES.md currently shows no X for a144 in that row; the fixture data and this device's firmware may differ.

Checks

  • uv run pytest: 2371 passed
  • ruff check and ruff format --check: clean
  • mypy: no errors in the changed files

Reads get_clean_sequence into CleanSequence.rooms and writes it with
set_clean_sequence. Gated on is_order_clean_supported (robot feature 123).
@Lash-L Lash-L added Small PR Small pull request (<200 lines) Feature New feature V1 V1 platform labels Nov 18, 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.

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

Review Summary

Clean, well-scoped PR adding CleanSequenceTrait (device.v1_properties.clean_sequence) and CleanSequence. One functional API gap turned up during RR_API cross-verification, plus a small test-coverage gap.

Priority 1: Public Trait APIs & Consumer Contracts

  • Good: CleanSequence subclasses RoborockBase with @dataclass, avoids Any/TypedDict/forward refs, keeps transport isolated via V1TraitMixin, and gates initialization on requires_feature = "is_order_clean_supported".
  • Finding (clean_sequence.py): set_order() rejects an empty list ([]) with ValueError, which prevents consumers from clearing/resetting a custom room cleaning order back to the robot's automatic sequence (see inline comment).

Priority 2: Data Lifecycle & State Management

  • Good: CleanSequenceConverter.convert() is a pure value-returning helper; set_order() performs a defensive list(rooms) copy and only updates self.rooms optimistically after send_command succeeds (so firmware rejections like -10007 leave local state unchanged).

Priority 3: Wire Protocols & RR_API Verification

  • Verified against official Roborock app bundles (both legacy com.roborock.tanos and modern Saros 10R bundles):
    • RPCs & wire shape: get_clean_sequence (params [] → returns list[int], [] when no custom order is set) and set_clean_sequence (params list[int]).
    • Reset semantics: Both bundles' onResetOrder() handler explicitly sends set_clean_sequence with params=[] to clear the custom cleaning sequence and restore automatic ordering.
    • Feature flag: isOrderCleanSupported() checks robot feature 123 (is_order_clean_supported in roborock/device_features.py).

Tests & Fixtures

  • Colocated at tests/devices/traits/v1/test_clean_sequence.py using shared fixtures and @pytest.mark.parametrize.
  • Finding (test_clean_sequence.py): Add behavior-driven coverage for an unsupported device (clean_sequence_trait is None) and for refresh() returning [] (plus updating the empty-list expectation once set_order([]) / reset is supported).

cleaning or moving; set it while the device is idle or docked.
"""
if not rooms or len(set(rooms)) != len(rooms):
raise ValueError(f"rooms must be a non-empty list of distinct segment ids: {rooms!r}")

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 — Public Trait API / Protocol Parity (set_clean_sequence reset semantics)

Rejecting rooms=[] prevents consumers from clearing a custom cleaning order back to the robot's automatic sequence. In the official Roborock app (verified in both legacy com.roborock.tanos and modern Saros 10R app bundles), onResetOrder() explicitly calls set_clean_sequence with [] ("After deleting cleaning order settings, the robot will create an optimum sequence automatically"), and get_clean_sequence likewise returns [] when no custom order is set.

Consider allowing [] in set_order (only rejecting duplicate segment IDs) — and optionally exposing a convenience reset_order() / clear_order() method if you prefer an explicit helper:

        if len(set(rooms)) != len(rooms):
            raise ValueError(f"rooms must contain distinct segment ids: {rooms!r}")
        await self.rpc_channel.send_command(RoborockCommand.SET_CLEAN_SEQUENCE, params=list(rooms))
        # Optimistic update to avoid an extra refresh
        self.rooms = list(rooms)


def test_requires_feature() -> None:
"""The trait is only created on devices that report order cleaning (robot feature 123)."""
assert CleanSequenceTrait.requires_feature == "is_order_clean_supported"

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.

Tests — Behavior-driven feature-gating & empty-list coverage

Per AGENTS.md (Behavior-Driven Assertions) and sibling optional-trait suites (test_customize_clean_mode.py, test_mop_dryer.py, test_dust_collection_mode.py), consider testing end-to-end discovery on an unsupported device (the default S7 MaxV fixture has is_order_clean_supported=False):

async def test_unsupported_clean_sequence(
    clean_sequence_trait: CleanSequenceTrait | None,
) -> None:
    """Trait is not initialized when is_order_clean_supported is False."""
    assert clean_sequence_trait is None

It would also be helpful to cover refresh() when the device returns [] (no custom cleaning order set), and update test_set_order_rejects_bad_input if set_order([]) is allowed to clear the order.

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

Lash-L commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

I tested this branch on a real Qrevo MaxV 2 (roborock.vacuum.a87, firmware 02.34.04, US region) and checked it against the a87's own app plugin (US product 110), which I downloaded and decompiled. The trait itself works: get_clean_sequence returned [20, 18, 17, 16, 19], set_order with two rooms swapped was stored and read back, the original order was restored, and a repeated room was refused before anything was sent.

This is an automated review and can be incorrect. If anything here looks wrong, please reply and say so.

The app has a second condition the gate is missing

In the app, isOrderCleanSupported is isSupportFeature(123) && isModelOrderSupported(). isModelOrderSupported() works like this:

  • No deviceLocation: false.
  • RubyPlus, RubySC, RubySLite, Tanos, TanosE or TanosV: true.
  • Any other product: !isFCC(), where isFCC() is deviceLocation == 'us'.

deviceLocation comes from app_get_init_status → local_info.location.

This Qrevo reports feature 123 and local_info.location: 'us', so the app hides room order, but this PR creates CleanSequenceTrait for it. Both the a87 plugin and the newer Saros Z70 (a179) plugin have the same rule. The Saros 10R tested in the description is presumably not a US unit, so it wouldn't show this.

The robot does accept and store the order. I haven't checked whether it follows that order in a clean, because I didn't run one.

Suggestion: add the location and product condition to the gate. DeviceFeaturesTrait already reads app_get_init_status, which includes local_info.location.

…ion rule

- set_order([]) now clears the custom order (the app's onResetOrder sends
  set_clean_sequence []); reset_order() is a helper for it. A repeated room
  is still refused.
- is_order_clean_supported now also needs the app's isModelOrderSupported():
  no location -> False; RubyPlus, RubySC, RubySLite, Tanos, TanosE, TanosV ->
  True; any other product only when local_info.location is not 'us'.
  DeviceFeaturesTrait passes local_info.location from app_get_init_status;
  location=None (offline callers) skips the rule.
- Tests: unsupported device, empty response, reset, and the model/region
  table. Five snapshots flip isOrderCleanSupported to False for the US
  fixture device, as the app would.
@github-actions github-actions Bot added the Data model changes Changes to data models, device info, or feature mappings label Nov 27, 2026
@cptntrps

Copy link
Copy Markdown
Contributor Author

Thanks @Lash-L, both reviews were right. Pushed 7780680:

Reset

  • set_order([]) now clears the custom order (same as the app's onResetOrder, which sends set_clean_sequence []), and reset_order() is a helper for it. A repeated room is still refused before anything is sent.
  • Hardware check tonight on a Saros 10R (a144): order [8,7,3,10,1,9] → set_clean_sequence [] → ok, get_clean_sequence → [] → original order restored and read back.

Gate

  • is_order_clean_supported is now feature 123 and the app's isModelOrderSupported(): no location → false; RubyPlus, RubySC, RubySLite, Tanos, TanosE, TanosV → true; any other product only when local_info.location != "us".
  • DeviceFeaturesTrait passes local_info.location from app_get_init_status. location=None (offline callers such as the CLI feature table) skips the rule.
  • You guessed right that my test unit would not show this, but for the opposite reason: it is a US unit (a144 is CoralPro, local_info.location: "us"), so with this change it no longer gets the trait, which matches the app. It accepts and stores the order all the same, like your a87.

Tests

  • Unsupported device (default S7 MaxV fixture → None), an empty get_clean_sequence response, reset via both reset_order() and set_order([]), and a table for the model/region rule.
  • Five snapshots flip isOrderCleanSupported to False for the US fixture device, as the app would.
  • Full suite: 2382 passed; ruff clean. mypy shows the same 10 missing-stub errors with and without this change.

Still needs hardware testing

  • Whether a robot actually follows a custom order during a clean. I have not run a clean with it either; both the a87 and the a144 store it, but that does not prove they use it.
  • A non-US unit, and a Ruby or Tanos unit in the US, to confirm the positive side of the rule.
  • One limit: cached DeviceFeatures from before this change keep True until features are rediscovered, because no field was added.

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

Data model changes Changes to data models, device info, or feature mappings Feature New feature /review run Code review skill (/review) has been run Small PR Small pull request (<200 lines) V1 V1 platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants