Skip to content

feat(v1): add carpet mode - #1092

Draft
infy1995 wants to merge 4 commits into
Python-roborock:mainfrom
infy1995:feat/v1-carpet-mode
Draft

infy1995 wants to merge 4 commits into
Python-roborock:mainfrom
infy1995:feat/v1-carpet-mode

Conversation

@infy1995

@infy1995 infy1995 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #738.

What changes

Adds a V1 carpet_clean_mode trait for the global carpet setting that the Roborock app offers: Avoid, Vac & Mop, Vacuum Only and Cross.

  • CarpetCleanModeTrait reads get_carpet_clean_mode plus the carpet first and cross flags from get_prop ["get_status"], and exposes mode, options and set_mode(). Options are gated by the device features, so a robot only offers what it supports. vacuum_only_settings_available tells callers whether the robot currently accepts the Vacuum Only extras.
  • A derived field is_carpet_clean_mode_supported gates the trait: it is off for a TanosSLite in the US region (covered by tests only, no such device here).
  • Two more derived DeviceFeatures fields (is_self_adaption_carpet_supported, is_dynamic_adaption_carpet_supported) decide whether Vacuum Only is offered and which value it writes. They depend on the robot's region and product, so from_feature_flags takes an optional location. These derived fields are left out of the SUPPORTED_FEATURES.md table, since the CLI has no region to compute them.
  • set_mode writes only the mode and the cross flag (carpet boost and deep clean are left as they are), then refreshes. Avoid and Vac & Mop send only the mode. Vacuum Only sends mode 3 (or 1 without dynamic adaption) and then turns cross off. Cross sends only the cross flag. A mode the robot does not offer raises RoborockUnsupportedFeature and sends nothing.
  • V1VacuumSimulator gets the four handlers and clears cross on Avoid and Vac & Mop like the robot does.
  • Docs: docs/V1_API_COMMANDS.md and docs/V1_DEVICE_FEATURES.md.

The first commit is a separate fix: cached device features written by an older version are read from the robot again. Without it, a pickled cache would make feature discovery raise for the new gate field.

Why

Carpet mode is the first global carpet setting for Home Assistant. A single select needs one trait that knows which options to show and how to write them without leaving the cross flag in a stale state.

App cross-check

The options, the gate rules and the command sequences were compared with the Roborock app plugin.

Tested on a device

Roborock Saros 10R, with the robot docked and its state restored afterwards: get_carpet_clean_mode, set_carpet_clean_mode, app_set_cross_carpet_cleaning_status and get_prop ["get_status"].

  • Avoid and Vac & Mop clear the cross flag by themselves.
  • Mode 3 leaves cross on, so Vacuum Only sends the extra cross-off write.
  • set_mode read back correctly for all four modes.

Behavior notes

  • A robot with no known region is treated as "other region": Vacuum Only is offered and writes 1.
  • If the get_prop read fails, the clean mode is still updated and the known carpet first and cross flags are kept.
  • An unknown carpet_clean_mode gives mode = None and no exception.
  • Cached device features written by older versions lack the new fields and are read from the robot again.

Conflicts with open PRs

Checked with git merge-tree against each open PR touching the same files. All are textual conflicts; whoever merges second rebases.

Checks

uv run pytest (2993 passed) and uv run pre-commit run --all-files (ruff, mypy, codespell) pass.

@infy1995 infy1995 mentioned this pull request Nov 24, 2026
9 tasks
@Lash-L

Lash-L commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Hi @infy1995! Will review this shortly, but consider joining our Roborock contributor discord to stay in touch and have easier access to us! https://discord.gg/8ytF2t5F

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

Summary

Verdict: Passes /review with nits.

Reviewed 76cfa08 (3 commits on main). This is a clean, well-scoped trait. The wire claims match the Roborock app plugin (com.roborock.tanos), tests are table-driven and use the shared fixtures plus V1VacuumSimulator, and the local run is green. None of the points below block the merge.

Checked against the app plugin (RR_API/nonhermes/com.roborock.tanos/output/, and the hermes bundle module_443.js gives the same gate logic):

  • set_carpet_clean_mode is sent as an object {"carpet_clean_mode": t}, and get_carpet_clean_mode takes []: confirmed, 448.js:1246-1258.
  • app_set_cross_carpet_cleaning_status {"status": t}: confirmed, 448.js:296-303.
  • Codes 0 avoid / 1 self adaption / 2 ignore ("Vac & Mop") / 3 dynamic adaption: confirmed, 461.js:231-236.
  • switch_status bit 0x08 is carpet first and 0x20 is cross: confirmed, 381.js:577-578.
  • is_self_adaption_carpet_supported / is_dynamic_adaption_carpet_supported, which use us=FCC and de=CE, the FCC dynamic list, the CE self list and the deep clean gate: confirmed, 402.js:137-171,695-710. Under these rules the two values can never both be true, so the PR choosing "dynamic if supported, else self" for Vacuum Only gives the same result as the app's "self if supported, else dynamic" (2406.js:321-330).
  • The Cross option is gated on CarpetCustomClean (bit 49): confirmed, 2559.js:1304,1836-1838. After writing 1 or 3, the app turns cross off only when that bit is set: confirmed, 2559.js:684-693.
  • Gating the trait on is_carpet_supported (robot_new_features & 512): confirmed, 402.js:319-322.

Overlap and stacking: #1092 is not stacked on #1054, #1055 or #1064, since none of those heads is an ancestor of it. It does not duplicate #1086: #1086's CarpetBoostTrait uses get_carpet_mode/set_carpet_mode (the boost and motor tuning setting), while this PR uses get/set_carpet_clean_mode and the cross flag, with no shared commands or models. The only conflict is the textual one in roborock/devices/traits/v1/__init__.py, between the neighbouring trait registration lines. The PR merges cleanly into current main.

Priority 1: Public Trait APIs & Consumer Contracts

  1. set_mode leaves carpet boost and carpet deep clean on, which the app does not do. roborock/devices/traits/v1/carpet_mode.py:83-107
    In the app, choosing Avoid or Vac & Mop (any mode other than 1 or 3) calls resetCarpetOtherSets() (2559.js:684), and turning Cross on calls resetCarpetOtherSets(true) (2559.js:913). Both turn off carpet deep clean and carpet pressurize, which is the #1086 boost sent through set_carpet_mode (2559.js:1588-1620, 492-519). With this PR, a Home Assistant user who picks Avoid keeps boost or deep clean on, a combination the app never leaves. From the bundle I cannot tell whether the firmware ignores those settings in that state or acts on them.
    Fix (either works): add a short line to the set_mode docstring saying that boost and deep clean are left as they are, so consumers know to refresh carpet_boost after the call (and the docs table records it). Or, once #1086 lands, mirror the app's reset in a follow-up. If you have the Saros 10R at hand, it is worth checking whether get_carpet_mode enable changes on its own after set_carpet_clean_mode 0.

  2. Question on naming: PropertiesApi.carpet_mode (roborock/devices/traits/v1/__init__.py:193) wraps carpet_clean_mode, but RoborockCommand.GET_CARPET_MODE/SET_CARPET_MODE are the boost commands that #1086 wraps as carpet_boost. Once both land, carpet_mode and get_carpet_mode will refer to different settings. Would carpet_clean_mode be a clearer attribute name? This is the maintainers' call. The current name does match the app's user-facing label.

Priority 2: Data Lifecycle & State Management

  1. Small gate gap (TanosSLite in the US). roborock/devices/traits/v1/carpet_mode.py:29
    The app hides the carpet settings view for TanosSLite in the FCC region (402.js:173-178, shouldShowCarpetSettingView). This trait is gated only on is_carpet_supported, so a US TanosSLite would still expose it. This is low impact. If you want to match the app, add a check in PropertiesApi or fold it into the derived feature computed next to the two adaption fields.

No lifecycle concerns. refresh() returns early on a get_prop failure and keeps the last known flags, as the PR body says. set_mode writes and then refreshes, matching sibling traits. The two new required DeviceFeatures fields make an older dict cache come back as None from from_dict, which triggers rediscovery (I checked this locally). The PR body already covers the pickled-cache case.

Priority 3: Wire Protocols, Codecs & Resilient Enums

No findings. CarpetCleanMode is a RoborockEnum with unknown = -1, so an unexpected code gives mode = None and does not raise.

Tests & PR hygiene

  • Tests sit in the mirror paths (tests/devices/traits/v1/test_carpet_mode.py, tests/data/v1/test_v1_carpet.py). They use @pytest.mark.parametrize, the shared mock_rpc_channel and device fixtures, and a simulator round trip, and they assert on public properties and the emitted commands.
  • Local run at 76cfa08: pytest 2861 passed (168 snapshots), and ruff check is clean. mypy reported 3 errors, all from the local environment (missing yaml/protobuf stubs and an existing error in a test file this PR does not change), none in the changed files. CI lint and tests are green.
  • The commit messages follow Conventional Commits, and the PR body lists conflicts with the other open PRs accurately.

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

@infy1995

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three points are addressed in the updated branch:

  1. Boost and deep clean: it differs between app plugin versions. In the one for the Saros 10R (and others like it), choosing Avoid, Vac & Mop or Cross does not write carpet boost or deep clean, while in other versions the app turns both off right away. Since there is no single behaviour, set_mode changes only the mode and the cross flag; I added that to the docstring and the docs. On a Saros 10R, setting Avoid left both settings unchanged. If you would prefer the library to turn them off, I can do it in a follow-up once the boost and deep clean traits are in.
  2. Naming: agreed, carpet_clean_mode matches get_carpet_clean_mode and avoids the clash with the boost commands. Renamed the attribute, module and trait class (CarpetCleanModeTrait).
  3. TanosSLite in the US: done. The trait is now gated on a derived feature that is off for a TanosSLite registered in the US region. I have no such device, so it is covered by tests only.

Also added a small fix(v1) commit: a stale pickled device cache missing newer feature fields would fail in discover_features, so those features are now rediscovered.

@infy1995
infy1995 force-pushed the feat/v1-carpet-mode branch from 1c68fea to dc4c634 Compare November 25, 2026 22:15
@github-actions github-actions Bot added documentation Improvements or additions to documentation Data model changes Changes to data models, device info, or feature mappings V1 V1 platform labels Nov 25, 2026
@infy1995
infy1995 marked this pull request as draft November 26, 2026 17:54

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 documentation Improvements or additions to documentation 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.

2 participants