Skip to content

Keep each robot's last-known state and serve it at /user/devices/{duid}/last_known - #251

Open
virtitnerd wants to merge 7 commits into
Python-roborock:mainfrom
virtitnerd:pr/last-known-state
Open

virtitnerd wants to merge 7 commits into
Python-roborock:mainfrom
virtitnerd:pr/last-known-state

Conversation

@virtitnerd

Copy link
Copy Markdown
Contributor

Why

A robot that loses Wi-Fi, gets stuck or is switched off stops answering, and from then on nothing says where it
was or what it last reported. A client has no way to show anything for it, and no way to tell "never paired" from
"paired but offline right now".

What

The server keeps, per robot and across restarts: when it last spoke and when its connection last closed, the last
status it sent (state, battery, error), its last position and the map it was drawn on, and its room table with the
room names from the home data. It is fed from the MQTT proxy (status pushes, the answers to get_status and
get_room_mapping, and the decrypted get_map_v1 reply) and seeded from the existing MQTT log on startup.

GET /user/devices/{duid}/last_known returns it. data.known is false for a robot the server has never heard
from. ?map=1 adds the last map.

Testing

New tests cover the store, the route and the room table. Full suite: 480 passed. I also used it daily against a
Qrevo Pro and a Qrevo Curv 2 Flow.

Notes

  • The firmware install PR depends on this one: it records the firmware version a robot reports in the same store.
  • Docs: docs/last_known_state.md.

virtitnerd and others added 7 commits November 15, 2026 16:15
The last status, battery and error a robot sent, its last position and the map it was on,
and when it last spoke or went offline, written under device_snapshots/ so it survives a
restart. A robot that dies or loses Wi-Fi stops answering; this is what is left to say
where it was.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Robot-originated frames update the store: status pushes (dps 120/121/122), get_status
answers, and the map reply, which is decrypted with the nonce of whichever client's
request asked for it. A closing robot connection marks the device offline at once.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Returns status, position, last_seen_at and offline_at; ?map=1 adds the last map the robot
sent so a client can draw it while the robot cannot be asked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A robot that went quiet before the store existed still has its last status, battery and map
in the decoded MQTT log. On startup, in a background thread, devices the store has no snapshot
for are filled in from that log: last time heard, last status, and the last map decoded with
the nonce of the request that asked for it. Devices that already have a snapshot are left alone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…h it

The snapshot had the last map but not which segment is which room, so an
offline map could only show generic labels. The proxy now records each
get_room_mapping answer, the startup seed reads it from the MQTT log, and
/last_known adds each room's name from the home data.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both calls return the same status object, so either one now updates the stored state.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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 PR adding capability; under this two-type scheme also covers additive documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants