Skip to content

fix(devices): default the device time zone to the server time zone - #294

Merged
Lash-L merged 4 commits into
Python-roborock:mainfrom
Hoeze:fix/device-timezone
Nov 28, 2026
Merged

Lash-L merged 4 commits into
Python-roborock:mainfrom
Hoeze:fix/device-timezone

Conversation

@Hoeze

@Hoeze Hoeze commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Devices without their own time zone now get network.timezone if set, else the time zone of the region (for example Europe/Berlin for eu). Before, they got America/New_York in the home data and in /user/devices/<duid>.

Problem

network.timezone and the region reached only the /location route (#123). The device lists used a fixed America/New_York for every device that had no time zone of its own.

Change

  • New default_timezone(ctx) in shared/data_helpers.py. It holds the region table that was in routes/bootstrap/location.py. For a region without its own time zone, it falls back to DEFAULT_TIMEZONE.
  • The /location route, the home data and /user/devices/<duid> all use it. DEFAULT_TIMEZONE stays in shared/constants.py, so open PRs that import it still work.
  • A time zone set on the device still wins.
  • GET /user/devices/<duid>/jobs computes nextFireTime with default_timezone too. The schedule runner of Add server-side scheduling that runs jobs the way the cloud does #179 picks its zone the same way, so nextFireTime names the time the job runs. Take an eu server without network.timezone and a job at 08:00 without timeZoneId. Without this change, the job runs at 08:00 in Berlin, but its nextFireTime names 08:00 in New York.
  • config.example.toml says that timezone also applies to devices. It also asks users to set it if their time zone differs from the region default, such as Europe/London in the eu region.
  • tests/conftest.py: write_release_config takes region and timezone options.

#179 is now on main. Its schedule runner already calls default_timezone when that exists. So with this PR, a schedule without its own time zone runs in network.timezone if set, else in the region's time zone, for example Europe/Berlin in the eu region. #213 and #214 import DEFAULT_TIMEZONE. They still work after this PR, but they keep America/New_York until they switch to default_timezone(ctx).

For the release notes: a schedule without its own timeZoneId moves on a server outside us without network.timezone. It now fires in the region's time zone, so in eu it fires about 6 hours earlier than before. Set network.timezone to keep another zone.

Before you open this PR (optional, but very helpful)

  • I checked for duplicates. I searched open PRs and issues and nobody else is already working on this.
  • I reviewed 1-2 other open PRs and tested whether they work on my vacuum.

PRs I reviewed:

Proof that it works

Tested on:

  • Vacuum model: Roborock Saros 20 Flow (roborock.vacuum.a307)
  • Firmware version: 02.17.50
  • Server version / commit: the device test ran on e839839 of my fork's a307-plugin branch. That build is upstream main 32608dd plus this PR, feat(api): enable scene tiles via productTags and category cardSpec #208 and my other fixes for the a307. The tests ran on this branch, rebased on upstream main f1e49fd.
  • Install method (Docker / Home Assistant add-on / other): built from source

What I did and what happened:

The change runs on my EU server. I have not checked a visible effect in the app, so the proof is the tests:

  • New test_device_time_zone_defaults_to_the_server_time_zone checks timeZoneId in the home data and in /user/devices/<duid> for four cases: eu gives Europe/Berlin, us gives America/New_York, timezone = "Europe/Vienna" wins over the region, and a device time zone of Asia/Tokyo wins over both.
  • test_device_jobs_endpoint_returns_imported_schedules now runs for us and eu. For eu, a job at 13:03 on Dec 15 gets the nextFireTime 12:03Z, which is 13:03 in Berlin. Without the nextFireTime change, it gets 18:03Z.
  • New test_server_timezone_without_a_configured_zone_uses_the_region_zone checks the zone of the schedule runner with the real default_timezone.
  • Full suite: uv run --extra dev pytest -q passes (727 tests).

Screenshots (required for any UI change)

No UI changes.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 20:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the region-aware time zone fallback changes to home data and device details.

No open issues 🎉

What changed in this PR

This PR extends the region-aware time zone behavior introduced for /location to home data and device details. Devices without their own time zone use network.timezone when configured, otherwise the region default; device-specific values remain unchanged.

Changes:

  • Centralizes time zone fallback logic in default_timezone(ctx) and reuses it across responses.
  • Adds regression coverage for regional defaults, configured overrides, and device-specific time zones.
  • Documents the expanded configuration behavior.
File Description
tests/​test_home_data_online.py Tests time zone defaults and overrides in home and device-detail responses.
tests/​conftest.py Adds region and time zone options to the configuration helper.
src/​roborock_local_server/​bundled_backend/​shared/​data_helpers.py Houses the shared time zone resolver and region mapping.
src/​roborock_local_server/​bundled_backend/​shared/​constants.py Removes the fixed device time zone constant.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​user/​devices/​service.py Uses the shared fallback for device normalization and details.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​bootstrap/​location.py Delegates time zone resolution to the shared helper.
src/​roborock_local_server/​bundled_backend/​https_server/​endpoint_rules.py Applies the shared fallback when normalizing home-data devices.
config.example.toml Clarifies that the time zone setting also applies to devices lacking one.

Review effort: Balanced

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: passed (nits)

Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.

Confirmed:

  • Defaults: devices without a time zone now get network.timezone, else the region default, in both home data and /user/devices/<duid>. An existing timeZoneId still wins, and the cloud import keeps it.
  • Field format: timeZoneId is an IANA name string in the APK's DeviceBean/DeviceBean2/DeviceRespBean.
  • Host-independent: the host time zone isn't used, so Docker or the HA add-on running in UTC makes no difference.
  • Robot behaviour is unchanged. V1 bundles set the robot's time zone from the phone (set_app_timezone), and timers and scenes read get_timezone from the robot. B01 bundles never read timeZoneId.

Unverifiable: the visible effect in the app.

Breaks #179 after merge. There's no text conflict, but #179 imports DEFAULT_TIMEZONE (jobs.py:8, schedule_runner.py:14), which this PR removes, so its schedule and timer tests fail with an ImportError. Either keep DEFAULT_TIMEZONE as an alias here, or have #179 switch to default_timezone(ctx); that's noted on #179 too. #213 and #214 need the same.

Nits:

  • eu always gives Europe/Berlin, an hour off for the UK, Ireland and Portugal. The docs could tell those users to set network.timezone.
  • The default at service.py:632 is never reached.

Checks: all 506 tests pass. It merges cleanly with #292 and #293. #295 conflicts on an import line in endpoint_rules.py.


This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles, refreshed 2026-11-21), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.

@Lash-L Lash-L added the passed auto review Automated review found no blocking issues label Nov 22, 2026
@Hoeze

Hoeze commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Devices without their own time zone got America/New_York in the home
data and in the device detail. network.timezone and the region reached
only the location route. The device lists now use the same default:
network.timezone if set, else the time zone of the region, for example
Europe/Berlin for eu.
Python-roborock#179, Python-roborock#213 and Python-roborock#214 import DEFAULT_TIMEZONE from shared.constants.
Removing it would break them with an ImportError, whichever PR merges
second. default_timezone now falls back to it instead of a new
FALLBACK_TIMEZONE, so the value stays America/New_York.

config.example.toml now asks users to set network.timezone if their
timezone differs from the region default, such as Europe/London in the
eu region.
GET /user/devices/<duid>/jobs computed nextFireTime in network.timezone,
else America/New_York. The schedule runner of Python-roborock#179 uses default_timezone,
which falls back to the region's zone. Take an eu server without
network.timezone and a job at 08:00 without timeZoneId: the job ran at
08:00 in Berlin, but its nextFireTime named 08:00 in New York. The route
now uses default_timezone too.
The comment that main has no data_helpers.default_timezone goes stale
with this branch, so it now says what the test covers.
@Hoeze
Hoeze force-pushed the fix/device-timezone branch from 43af641 to 6db64e9 Compare November 22, 2026 21:50

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: passed (nits)

Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.

Since the last review (9962136 → 6db64e9)

  • Breaks #179 after merge: fixed. DEFAULT_TIMEZONE stays in shared/constants.py:7, and default_timezone falls back to it (shared/data_helpers.py:80). #179 is now on main, and its server_timezone (shared/schedule_runner.py:167) picks up the real helper. #213 and #214 can still import the constant.
  • eu is an hour off for the UK, Ireland and Portugal: fixed. config.example.toml now tells those users to set network.timezone.
  • Unreachable default at service.py:632: kept on purpose (main has the same structure). Fine.
  • New: nextFireTime now uses the runner's zone. device_jobs_payload (routes/user/devices/service.py:734) calls default_timezone(ctx), the same zone the ScheduleRunner falls back to (schedule_runner.py:286). Before this change, an eu server without network.timezone showed a time in New York for a job the runner fires in Berlin.

Confirmed:

  • DST: in a scratch run, 0 8 * * * in eu gives 06:00Z in July and 07:00Z on the fall-back day. 30 2 * * * skips the missing 02:30 on 2026-03-29 and fires once, at the first 02:30, on 2026-10-25. us and unknown regions stay on America/New_York.
  • Host time zone isn't used. Nothing reads /etc/localtime or TZ, so a UTC or tz-less container gives the same result. network.timezone is checked at load time (config.py:225).
  • Field format: timeZoneId is a plain string in the APK beans (DeviceBean.java:268, DeviceBean2.java:1408, DeviceRespBean.java:239), and the server sends IANA names. Timers made in the app send timeZoneId: sharedCache().robotTimeZone (the zone the robot reports) in the job body, so the new default doesn't change them.
  • Schedules that store their own timeZoneId don't change. That covers jobs from POST .../jobs (jobs.py:86), timer RPCs (timer_rpc.py:198) and the app.

Unverifiable: the visible effect in the app, and whether the robot ever reads timeZoneId from home data.

Nits:

  • Existing schedules without a timeZoneId will move. On a non-us server without network.timezone, they now fire in the region's zone, for example 6 hours earlier in absolute time in eu. That's the intended fix, but add one line to the release notes or the add-on CHANGELOG so users aren't surprised.
  • tzdata (already true on main, not caused by this PR): ZoneInfo needs system zone data, and the image (python:3.11-slim) doesn't install tzdata explicitly. If a base image ever ships without /usr/share/zoneinfo, ZoneInfo raises an error. The schedule runner and nextFireTime then skip every job. Adding tzdata to dependencies in pyproject.toml would rule this out. That could go in a follow-up.

Checks: all 727 tests pass on 6db64e9. It merges cleanly with main and with #293. The two PRs touch different files, and #293 doesn't use time zones.


This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.

@Lash-L
Lash-L merged commit 75c0750 into Python-roborock:main Nov 28, 2026
3 checks passed
@Lash-L

Lash-L commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Good change, TY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

passed auto review Automated review found no blocking issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants