Skip to content

feat(v1): add collision avoidance traits - #1089

Merged
allenporter merged 1 commit into
Python-roborock:mainfrom
hCoureau:submit/feat/collision-avoidance-setting
Nov 25, 2026
Merged

allenporter merged 1 commit into
Python-roborock:mainfrom
hCoureau:submit/feat/collision-avoidance-setting

Conversation

@hCoureau

@hCoureau hCoureau commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds typed V1 traits for the collision avoidance setting (get_collision_avoid_status / set_collision_avoid_status), which previously could only be read or changed by sending raw commands.

  • CollisionAvoidanceTrait (device.v1_properties.collision_avoidance): an on/off switch (RoborockSwitchBase: is_on, enable(), disable()), backed by a new CollisionAvoidStatus RoborockBase model.
  • CollisionAvoidanceModeTrait (device.v1_properties.collision_avoidance_mode): for two-level devices. It decodes status into the new CollisionAvoidanceMode RoborockEnum (1 = high_coverage, 2 = less_collision, any other value → unknown, with the raw value kept in status; the labels are inferred, see Testing) and sets it with set_collision_avoidance_mode(mode). Passing unknown raises RoborockUnsupportedFeature and sends no command.

Setters update the cached value optimistically after the SET call, the same way ChildLockTrait and MopDryerTrait do.

Gating

  • collision_avoidance is created when is_avoid_collision_supported (robot new-features bit 134217728) is set and is_two_gears_no_collision_supported is not set.
  • collision_avoidance_mode is created when is_two_gears_no_collision_supported (new feature string bit TWO_GEARS_NO_COLLISION) is set.

Two-level devices get only the mode trait. They also report the on/off bit, and exposing both traits would give two controls over the same value. Because of the extra condition, the switch is created in discover_features() and skipped in the generic optional-trait loop, the same way ObstaclePhotoTrait is.

Testing

  • New tests/devices/traits/v1/test_collision_avoidance.py, which uses the shared device / mock_rpc_channel / discover_features_fixture fixtures with trait_home_data overridden through indirect parametrization. It covers:
    • discovery for on/off-only, two-level (with and without the on/off bit) and unsupported feature sets
    • refresh decoding, including an unrecognised mode value mapping to unknown
    • the SET payloads sent by enable() / disable() / set_collision_avoidance_mode()
    • rejection of unknown without sending a command
  • uv run pytest -n auto: 2834 passed, 46 xfailed.
  • ruff check, ruff format --check and mypy roborock tests are clean, apart from the existing tests/map/test_b01_q10_render.py:502 error that is already on main.

This hasn't been tested on hardware. The feature flags and command docs establish only that two-level devices exist and that status carries the value; nothing in the repo maps 1/2 to named levels. The high_coverage / less_collision labels are inferred, and unrecognised values decode to unknown with the raw value kept in status.

Related open PRs

#1036 and #1045 also edit the "skip traits created above" line in PropertiesApi.discover_features() (and #1045 also edits the module import lists). Whichever lands second has a one-line conflict, resolved by adding both trait classes to the tuple.

🤖 Generated with Claude Code

get_collision_avoid_status and set_collision_avoid_status had no typed
trait, so consumers had to send raw commands to read or change the setting.

Add CollisionAvoidanceTrait, an on/off switch for devices that report
is_avoid_collision_supported, and CollisionAvoidanceModeTrait for devices
that report is_two_gears_no_collision_supported. The mode trait decodes
the value to CollisionAvoidanceMode (1 high_coverage, 2 less_collision,
other values unknown) and sets it with set_collision_avoidance_mode(),
which rejects unknown. Two-level devices do not get the switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hCoureau
hCoureau force-pushed the submit/feat/collision-avoidance-setting branch from 1b9294a to e29a563 Compare November 23, 2026 23:33
@allenporter
allenporter merged commit b436fcf into Python-roborock:main Nov 25, 2026
9 checks passed
@hCoureau
hCoureau deleted the submit/feat/collision-avoidance-setting branch November 26, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants