Repository navigation
feat: expose Q7 robot position - #1041
ramon-angosto wants to merge 4 commits into
Conversation
Lash-L
left a comment
There was a problem hiding this comment.
Automated code review by Gemini 4 Argon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).
PR Scoping & Branch Stack Note
- Stacked branch: This PR targets
mainand includes commits from #1038 (67ce5a1), #1039 (6bbd0cc), and #1040 (63c9290). This review is scoped to the head commit42e117a8e6c81cc16e602a06454a38cfb2b6bc40(feat: expose Q7 robot position). - Interaction with
main/ PR #1051: Bothmain(via #1042) and PR #1051 updateroborock/devices/rpc/b01_q7_channel.pyandroborock/protocols/b01_q7_protocol.pyto usecreate_map_response_assembler()for multi-partMAP_RESPONSEframes.Q7PushChannel.subscribe_device_pushesanddecode_device_pushare orthogonal to the map response assembler, so rebasing ontomain(and #1051) will only require a straightforward merge resolution in those two files.
Summary by Layer
- Protocol (
roborock/protocols/b01_q7_protocol.py): Cleanly decodes unsolicited*.postmessages on DP10001(RPC_RESPONSE,B01) intoQ7DevicePush(method, params), ignoring command responses (data/code) and non-dict payloads. - Channel (
roborock/devices/rpc/b01_q7_channel.py,roborock/devices/device_manager.py): Adds theQ7PushChannelprotocol andB01Q7Channel.subscribe_device_pushes, wired throughcreate_device_managerandQ7PropertiesApi.start()/close(). - Trait (
roborock/devices/traits/b01/q7/map_content.py,roborock/devices/traits/b01/q7/__init__.py):latest_position_from_cur_pathaccurately parses[start_index, x, y, phi, kind, ..., timestamp]samples fromprop.postcur_pathpushes and converts the latest(x, y)world coordinates (meters) viaQ7RoborockPoint.from_world.MapContentTrait.refresh_live()requests the live map viaservice.upload_by_maptypewith{"map_type": 0}, serialized underself._map_command_lock.
- Map Parser (
roborock/map/b01_map_parser.py):parse_robot_posefilters out both the out-of-bounds(1100.0, 1100.0)unlocalized placeholder and the(0.0, 0.0)task-startup placeholder. One minor consistency/efficiency suggestion is noted inline regarding_place_posesand double protobuf deserialization.
- Tests (
tests/devices/rpc/test_b01_q7_channel.py,tests/devices/traits/b01/q7/test_map_content.py): Good coverage ofsubscribe_device_pushes,cur_pathsample extraction, malformed/unrelated push filtering, placeholder pose rejection, andrefresh_live().
| if not parsed.HasField("mapHead") or not parsed.HasField("currentPose"): | ||
| return None | ||
| pose = parsed.currentPose | ||
| if (pose.x == 0.0 and pose.y == 0.0) or not _WorldToPixel(parsed).in_bounds(pose.x, pose.y): |
There was a problem hiding this comment.
Low — Align (0.0, 0.0) startup pose filtering between parse_robot_pose and _place_poses
parse_robot_pose rejects both out-of-bounds poses ((1100.0, 1100.0)) and the (0.0, 0.0) placeholder emitted while a task is starting, whereas _place_poses (line 191) only checks projector.in_bounds(parsed.currentPose.x, parsed.currentPose.y).
Because (0.0, 0.0) is typically inside mapHead bounds (minX <= 0 <= maxX, minY <= 0 <= maxY), a startup frame carrying currentPose = (0.0, 0.0) will leave MapContent.robot_position untouched here, but _place_poses will still place map_data.vacuum_position (and the rendered vacuum glyph) at world (0.0, 0.0) instead of falling back to map_data.charger.
Sharing a helper (e.g. _has_valid_current_pose(parsed, projector)) between _place_poses and parse_robot_pose would keep map_data.vacuum_position and MapContent.robot_position consistent on startup frames.
There was a problem hiding this comment.
Done in 49dd3f8: a shared _valid_current_pose() now decides both map_data.vacuum_position and robot_position, so a (0, 0) startup pose falls back to the dock in the rendered map too. The parser tests cover both placeholders.
| self.raw_api_response = raw_payload | ||
| # Saved maps and frames without a fix carry no usable pose: keep the last known one. | ||
| try: | ||
| pose = parse_robot_pose(raw_payload) |
There was a problem hiding this comment.
Low — raw_payload is deserialized twice in _parse_and_store
self._map_parser.parse(raw_payload) on line 166 already deserializes raw_payload into a RobotMap protobuf message (and raises RoborockException if decoding fails or mapHead is missing), and parse_robot_pose(raw_payload) here deserializes the same raw_payload a second time.
Consider either exposing the world robot pose on ParsedMapData / MapData during B01MapParser.parse(), or keeping parse_robot_pose as a fast path when full rendering is not needed.
There was a problem hiding this comment.
Done in 49dd3f8: B01MapParser.parse() stores the valid live pose (world meters) in map_data.additional_parameters[ROBOT_WORLD_POSITION], next to room_names, and MapContentTrait reads it from there. The separate parse_robot_pose() helper is removed, so each frame is deserialized once.
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.
Add a `RemoteTrait` to the Q7 properties API, mirroring the Q10 remote API. Manual mode is entered with `prop.set sweep_type=5` and the robot is driven with `service.set_direction` (1 forward, 2 left, 3 right, 0 exit). Each command moves the robot for a short burst, so callers repeat it while a direction is held. Leaving remote mode restores `sweep_type=0`.
Add `set_carpet_turbo` and `set_carpet_avoid` to the Q7 properties API. Both are written individually with `prop.set` (`carpet_turbo` / `carpet_avoid`) and reported back nested under `privacy`. Keep the user-visible `name` of each entry returned by `service.get_map_list`, which was previously dropped.
Add `MapContentTrait.robot_position` (common Roborock coordinates) for Q7 devices, kept up to date from two sources: - the current pose in live map frames (`currentPose`), ignoring the `(1100, 1100)` and `(0, 0)` placeholders the firmware reports when the pose is unknown or outside the map; - `cur_path` samples in unsolicited `prop.post` device pushes, which the device streams while a task is running. To receive those pushes, `B01Q7Channel` now implements a `Q7PushChannel` protocol that decodes `*.post` messages into `Q7DevicePush`, and `Q7PropertiesApi.start()` subscribes to them. Add `MapContentTrait.refresh_live()`, which requests the live map by type (`service.upload_by_maptype`). Unlike the saved map it carries the current pose and makes the device stream `cur_path` positions.
42e117a to
49dd3f8
Compare
Summary
Adds
MapContentTrait.robot_positionfor Q7 devices, in common Roborock coordinates (Q7RoborockPoint). It notifies the existing map content listeners when it changes. This is what Home Assistant needs forvacuum.get_current_position.The position comes from two sources:
currentPoseis used. The firmware reports(1100, 1100)or(0, 0)when the pose is unknown, so poses outside the map bounds or exactly at the origin are ignored and the last known position is kept.cur_pathdevice pushes. While a task runs, the device sendsprop.postpushes withcur_path: [start_index, x, y, phi, kind, ..., timestamp](world meters). The last sample is used.Changes
Q7DevicePushanddecode_device_push()inb01_q7_protocoldecode unsolicited*.postmessages.Q7PushChannelprotocol, implemented byB01Q7Channel.subscribe_device_pushes().Q7PropertiesApitakes apush_channeland subscribes to device pushes instart().B01MapParser.parse()stores the valid live pose (world meters) inmap_data.additional_parameters[ROBOT_WORLD_POSITION], next toroom_names, so the frame is deserialized only once. The same_valid_current_pose()check decides both the rendered robot glyph androbot_position, so a(0, 0)startup pose no longer draws the robot at the origin; it falls back to the dock like the(1100, 1100)placeholder.MapContentTrait.refresh_live()requests the live map by type (service.upload_by_maptype {"map_type": 0}). Unlike the saved map (upload_by_mapid), it carries the current pose, and it makes the device streamcur_pathpositions. Integrations can call it while the robot is cleaning to get an up-to-date map and position.Testing
cur_pathparsing (including malformed pushes), placeholder poses andrefresh_live().roborock.vacuum.sc05, firmware 03.01.80) while cleaning rooms and zones.