Skip to content

feat: add Q7 zone cleaning - #1038

Merged
Lash-L merged 1 commit into
Python-roborock:mainfrom
ramon-angosto:q7/1-zone-cleaning
Nov 21, 2026
Merged

Lash-L merged 1 commit into
Python-roborock:mainfrom
ramon-angosto:q7/1-zone-cleaning

Conversation

@ramon-angosto

@ramon-angosto ramon-angosto commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds zone cleaning to the Q7 (B01) properties API:

  • Q7PropertiesApi.clean_zone(first_corner, second_corner) cleans one rectangle.
  • Q7PropertiesApi.clean_zones([(first, second), ...]) cleans several rectangles in a single task.
  • New Q7RoborockPoint (common Roborock millimetre coordinates, map origin at (25500, 25500)) with from_world() / to_world() conversions to the Q7 world coordinates (meters, origin next to the dock, y pointing up). This keeps the public API in the same coordinate space as other Roborock devices.

Device protocol

The device needs three commands, in this order:

  1. service.set_preference_type {"prefer_type": 4} selects zone cleaning.
  2. service.set_zone_points {"zone_points": [x1, y1, x2, y1, x2, y2, x1, y2, ...]} sends the corners of each rectangle in world meters. Multiple rectangles are concatenated.
  3. service.set_zone_clean {"ctrl_value": 1} starts the task. ctrl_value: 0 stops it.

While the zone task runs, the device reports work_mode 30 (PLAN_AREA).

Testing

  • Unit tests cover coordinate conversion, single and multiple zones, and rejection of empty or zero-area zones.
  • Verified on a Q7 TF+ (roborock.vacuum.sc05, firmware 03.01.80) with one and two zones.

Fixes #992

@Lash-L Lash-L added Small PR Small pull request (<200 lines) Feature New feature Q7 B01 Q7 platform labels Nov 15, 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 Argon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).

Summary by Layer

  • roborock/data/b01_q7/ (Q7RoborockPoint):
    • Cleanly encapsulates the conversion between the common Roborock millimetre coordinate frame (origin at (25500, 25500)) and Q7 world coordinates in meters ((x - 25500) / 1000, (y - 25500) / 1000, with y-up matching Q7 map coordinates).
    • Exported in roborock/data/b01_q7/__init__.py, roborock/data/__init__.py, and roborock/devices/traits/b01/q7/__init__.py.
  • roborock/devices/traits/b01/q7/ (Q7PropertiesApi.clean_zone / clean_zones):
    • Accurately implements the 3-step Q7 zone cleaning command sequence: service.set_preference_type ({"prefer_type": 4}), service.set_zone_points ({"zone_points": [...]} with 8 world-meter floats per rectangular zone), and service.set_zone_clean ({"ctrl_value": 1}).
    • Validates non-empty zone lists and rejects degenerate zero-width/zero-height rectangles before issuing any RPC commands.
    • Minor suggestion: Reuse the already-imported CleanTaskTypeMapping.AREA.code (4) instead of defining a duplicate _ZONE_PREFERENCE_TYPE = 4 constant.
  • tests/:
    • Good unit test coverage in tests/data/b01_q7/test_b01_q7_containers.py and tests/devices/traits/b01/q7/test_init.py covering coordinate round-trips, single-zone and multi-zone command payloads, and pre-send validation errors.

]

# ``service.set_preference_type`` value that selects zone cleaning (``custom_type`` 4).
_ZONE_PREFERENCE_TYPE = 4

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.

CleanTaskTypeMapping is already imported in this module (line 14) and defines CleanTaskTypeMapping.AREA = ("zones", 4) in b01_q7_code_mappings.py. Using CleanTaskTypeMapping.AREA.code in clean_zones (similar to CleanTaskTypeMapping.ALL.code and CleanTaskTypeMapping.ROOM.code in start_clean and clean_segments above) avoids duplicating the constant here.

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.

Done in ad3991f: clean_zones now uses CleanTaskTypeMapping.AREA.code and the duplicated _ZONE_PREFERENCE_TYPE constant is gone.

min_x, max_x = sorted((x1, x2))
min_y, max_y = sorted((y1, y2))
zone_points += [min_x, min_y, max_x, min_y, max_x, max_y, min_x, max_y]
await self.send(RoborockB01Q7Methods.SET_PREFERENCE_TYPE, {"prefer_type": _ZONE_PREFERENCE_TYPE})

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.

Suggested change
await self.send(RoborockB01Q7Methods.SET_PREFERENCE_TYPE, {"prefer_type": _ZONE_PREFERENCE_TYPE})
await self.send(RoborockB01Q7Methods.SET_PREFERENCE_TYPE, {"prefer_type": CleanTaskTypeMapping.AREA.code})

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.

Applied (ad3991f).

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

Lash-L commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Hi @ramon-angosto - please take a look at the automated feedback. Once you're done, mark the PR as ready for review and I will take a look myself! Going ahead and doing this for all your PRs

@Lash-L
Lash-L marked this pull request as draft November 15, 2026 19:56
Add `clean_zone` and `clean_zones` to the Q7 properties API. Zones are given
as two opposite corners in the common Roborock millimetre coordinate space
through a new `Q7RoborockPoint`, which converts to and from the Q7 world
coordinates (meters, origin next to the dock).

The device expects the zone preference type to be selected first
(`service.set_preference_type`), then the zone corners as a flat list
(`service.set_zone_points`), and finally `service.set_zone_clean` to start.
Several zones are concatenated into a single task.
@ramon-angosto
ramon-angosto marked this pull request as ready for review November 16, 2026 08:07

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

Follow-up review on commit ad3991f, including cross-verification against the Roborock Q7 app bundle and Q7 (roborock.vacuum.sc05) firmware. Prior Nov 15 feedback (reusing CleanTaskTypeMapping.AREA.code instead of a duplicate _ZONE_PREFERENCE_TYPE constant) has been addressed.

Summary by Architectural Layer

  • Priority 1 — Public Trait APIs & Consumer Contracts (roborock/data/b01_q7/b01_q7_containers.py, roborock/devices/traits/b01/q7/__init__.py):
    • Q7RoborockPoint cleanly subclasses RoborockBase as a @dataclass with concrete int coordinates and from_world() / to_world() conversions, keeping the public API in the consumer-agnostic millimetre coordinate space ((25500, 25500) origin) consistent with V1 and Q10.
    • Q7PropertiesApi.clean_zone and clean_zones are strongly typed with no Any leakage and properly export Q7RoborockPoint via __all__.
  • Priority 2 — Lifecycle, State & Concurrency (roborock/devices/traits/b01/q7/__init__.py):
    • Input validation (non-empty zones, non-degenerate rectangles) runs upfront before any RPC is sent, avoiding partial command side effects.
    • Linear, direct 3-step await self.send(...) flow with no hidden state mutation or lifecycle leaks.
  • Priority 3 — Wire Protocol & Firmware Verification:
    • Command sequence & payloads: Cross-verified against the Roborock Q7 app bundle (_startZoneClean / _setAndStartZoneClean) and Q7 (roborock.vacuum.sc05) firmware (CAiotParseBuf): service.set_preference_type ({"prefer_type": 4} via CleanTaskTypeMapping.AREA.code) → service.set_zone_points ({"zone_points": [...]} as a flat float array of 4 (x, y) world-meter corners per zone, matching the firmware's Part_%d :[%f,%f],[%f,%f],[%f,%f],[%f,%f] parser) → service.set_zone_clean ({"ctrl_value": 1} via SCDeviceCleanParam.START.code).
    • Coordinate space: Confirmed world meters with y-up matches B01MapParser (_WorldToPixel), and canonical rectangle corner ordering [min_x, min_y, max_x, min_y, max_x, max_y, min_x, max_y] aligns with the rest of the codebase.
  • Tests (tests/data/b01_q7/test_b01_q7_containers.py, tests/devices/traits/b01/q7/test_init.py):
    • Properly mirrored under tests/, using fake_channel and @pytest.mark.parametrize to verify coordinate round-trips, single/multi-zone command sequences, and pre-send validation errors.

No defects found — this PR is clean and ready to approve.

@Lash-L Lash-L added the Passed /review Passed the /review skill check label Nov 21, 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.

TY @ramon-angosto - this looks good and seems to be working for me!

@Lash-L
Lash-L merged commit e9d8b34 into Python-roborock:main Nov 21, 2026
9 checks passed
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 Q7 B01 Q7 platform /review run Code review skill (/review) has been run Small PR Small pull request (<200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Q7 (B01 / sc01): working zone cleaning command format (set_zone_points + set_zone_clean)

2 participants