Skip to content

feat: add Q7 zone cleaning - #1038

Open
ramon-angosto wants to merge 1 commit into
Python-roborock:mainfrom
ramon-angosto:q7/1-zone-cleaning
Open

ramon-angosto wants to merge 1 commit into
Python-roborock:mainfrom
ramon-angosto:q7/1-zone-cleaning

Conversation

@ramon-angosto

Copy link
Copy Markdown

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.

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

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

Feature New feature 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.

2 participants