Repository navigation
Add server-side scheduling that runs jobs the way the cloud does - #179
virtitnerd wants to merge 9 commits into
Conversation
297fc12 to
59bf2e6
Compare
59bf2e6 to
1cf1dd1
Compare
|
A status note, in case it helps with review: this PR is still mergeable and clean against main after today's commits, and I have not needed to change it since the last push. Other work now builds on it, so it is the piece the rest is waiting for:
If it is easier to review in pieces, I can split it: the store and its API first, then the executor that fires jobs. Just say which you would prefer, or point me at anything you want changed first. |
a14aa15 to
ce54133
Compare
|
Test report: S6 MaxV ( Before this PR (on
With this PR
One rough edge: right after a container restart, |
|
Thanks for the thorough test. I fixed the restart traceback: a timed-out MQTT read was being caught by the save-failure handler because TimeoutError is an OSError, so it now logs quietly at debug level and only real save failures warn. I'm leaving the full-entry timer format as an observation for now, since the sync only replays what the app sent. |
The map backup and capabilities probes reach the robot through the routine runner's get_routine_runner(), which comes with the schedule store (Python-roborock#179). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@C9H13NO3-dev I appreciate you testing out this PR! @virtitnerd - this PR has conflicts now, can you fix? |
Split _run_scene so a scheduled job can run the same step executor without syncing scene IDs to the robot, and add start_job(), which refuses to interrupt a routine that is already running on the device. get_routine_runner() gives other callers the per-context instance. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit c657648)
Roborock's cloud fires server_scheduled_start jobs at nextFireTime. With the vacuum pointed at this server nothing did, so imported schedules never ran. ScheduleRunner evaluates each enabled job's cron in its own timezone and hands due jobs to the routine runner, carrying fan_power, water_box_mode and mop_mode so vac-only and vac+mop schedules behave as configured. One-shot jobs disable themselves after firing. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit b5203b2)
Start the scheduler alongside the other supervisor tasks and stop it on
shutdown. GET /user/devices/{id}/jobs now computes nextFireTime from the
cron instead of returning whatever value was captured at import time.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 14ddb5f)
schedule_store holds create/update/delete for the per-device jobs kept in the inventory, so the timer RPC handler, HTTP routes and dashboard can share one writer. Crons without their own timeZoneId now evaluate in the zone the robot is told by /location (America/New_York unless configured) rather than UTC, so a 11:00 schedule fires at 11:00 local. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit 0751a7b)
Timer RPCs carry each schedule's vac and mop settings, and a schedule keeps the official app's link to its server_timer entry (the robot-side id in its name) so writing it back goes to the right robot entry. The four get/set/upd/del_server_timer methods are left to the robot: a robot that speaks server_timer stores those schedules itself, and answering them from this store hid the robot's real schedules and, tried once, caused data loss (the official app deletes server_timer entries it does not recognize when its schedule screen opens). A parametrized test over all four methods keeps the interceptor's method list from regressing. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
POST /user/devices/{duid}/jobs creates a job (the call python-roborock
makes), and PUT/PATCH and DELETE on /jobs/{id} edit or remove one. The
GET matcher is now method-aware so a write no longer falls through to
the list route. Update and delete paths are not confirmed against the
official app; they follow the scene routes' conventions.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 5b83853)
A schedule's job (POST /user/devices/{duid}/jobs) carries a settings entry whose
"name" is the id of the matching timer the official app also saved on the robot.
The cloud runs such a job by sending server_scheduled_start with that entry, which
is the method name inside the job itself. The robot accepts it, runs the clean
(rooms or whole home) and records it as "Schedules" in its history; without the
entry it answers -10005 "Invalid timer", and with a bare id "Param should be name
+ fan + segment". python-roborock does not list the command, so it is sent through
a small SchedulerCommand enum.
A schedule with no robot-side id (one saved through the legacy set_timer), or one
the robot refuses, falls back to the plainer ways, since a refused command changes
nothing: a whole-home clean is one app_start carrying the schedule's fields plus
source 3, which the robot also records as "Schedules"; a room schedule is the
settings commands followed by a segment clean. Scenes and routines are untouched.
The new steps are produced only by schedules.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
asyncio.timeout raises TimeoutError, which is an OSError, so a read that timed out because the robot had not reconnected after a restart was logged as 'Could not save native schedule reconciliation' with a traceback. The read now has its own handler that logs at debug and returns, and only a failure to save the result still warns. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1927b43 to
a1a1991
Compare
|
Rebased on the current main and fixed the conflicts. Same 9 commits. The conflicts were in |
|
Follow-up test on the rebased head
Thanks for the quick fix! |
Problem
Roborock schedules are run by the cloud: the official app writes each one as a job (
/user/devices/{duid}/jobs) and the cloud starts the clean when it is due. Against this server those calls had nowhere to go, so clients like LocalRock saw no schedules, could never create one, and a schedule made in the official app never ran. This covers both the legacyget/set/upd/del_timerrobots and robots on the newerserver_timerprotocol.Changes
/jobscalls).get/set/upd/del_timeranswered from that store instead of being forwarded. Editing merges settings rather than resetting them; an empty action object leaves existing settings alone. One-time schedules (day and month pinned, e.g.15 23 18 10 *) are listed with their date, the form the robot and the official app use. A settings entry'sname, the official app's link to the robot-side timer, is kept so a client can find that timer to edit or delete it.name) is run the way the cloud runs it: the robot is sentserver_scheduled_startwith the job's settings entry. The robot accepts it for room and whole-home schedules, and for a room schedule it records the clean as "Schedules" in its history. A job without a timer id (one saved through legacyset_timer), or one the robot refuses, falls back to the plainer ways, which is safe because a refused command changes nothing: a whole-home clean is oneapp_startcarrying the schedule's fields plussource: 3(which the robot also records as "Schedules"), and a room schedule is the settings commands followed by a segment clean. Scenes and routines are untouched; the new step types are produced only by schedules.Deliberately out of scope
get/set/upd/del_server_timerare not answered from the store. They are forwarded to the robot, which keeps those entries and from which the official app reads them back. Answering them locally, which I tried and reverted during development, hid the robot's real schedules from every client, and the official app then deleted the entries it no longer recognized. A parametrized test guards that this stays so. What runs aserver_timerschedule here is its/jobsrecord, which the runner fires like any other job.How the start was found
The robot does not run a
server_timerentry by itself: with the runner told to skip those jobs, four scheduled times passed with the robot idle. So the server has to start them. Starting a clean with the settings commands and an emptyapp_startworks but the robot records it as started by "App". Sendingserver_scheduled_start(the method name inside the job) with only the job's settings is refused with-10005 "Invalid timer", and with a bare id with"Param should be name + fan + segment"; with the job's whole settings entry includingnameit runs (a room schedule's history reads "Schedules | Rooms"). Separately,app_starttakes asourcefield andsource: 3is recorded as "Schedules" (other spellings tried, such asstart_type, are ignored).Related
#88 is the same territory; I held this back for a bit specifically to avoid stepping on that work. Happy to coordinate however's easiest, this doesn't need to be the one that lands if yours is further along, consider it an alternative or reference rather than a race.
Tested
pytest: 458 passed. Verified live on a Roborock Qrevo. End to end: a one-time whole-home schedule created from LocalRock was run by the server at its scheduled minute with exactly one command,server_scheduled_startcarrying the job's settings entry, which the robot answeredok; the robot's history shows it as "Schedules | Full". Commands sent to the robot directly:server_scheduled_startfor a room schedule (history: "Schedules | Rooms"), andapp_startwithsource: 3(history: "Schedules | Full"). The fallback paths are covered by unit tests against a fake robot that answers-10005.