Skip to content

fix: let the device plugin of the Android app load the map - #292

Merged
Lash-L merged 5 commits into
Python-roborock:mainfrom
Hoeze:fix/plugin-map-loading
Nov 28, 2026
Merged

Lash-L merged 5 commits into
Python-roborock:mainfrom
Hoeze:fix/plugin-map-loading

Conversation

@Hoeze

@Hoeze Hoeze commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

With these changes, the device plugin of the Android app (4.60.06) loads the map from a local server. Before, it stayed on its map loading screen. It needs both:

  • The local login answer now carries "region" (for example "eu") and a real country ("DE" for the EU region). Before, it had no "region" and answered "country": "EU", so the plugin's country lookup failed.
  • /api/v5/product now answers "agreements" with USER_AGREEMENT and PRIVACY_POLICY, at the versions that /api/v1/checkAppAgreement reports as signed. Before, it answered [], so the plugin's agreement check failed.

Problem: the region

The app stores "region" and "country" of the login answer. The device plugin reads them as serverCode and countryCode in fetchCountryInfo.

Without "region", the plugin looks up its own area table by the country code. "eu" is not in that table, so the lookup throws. The plugin retries at once and loops without sending any request.

#240 described the same symptom with a different cause: identical MQTT client ids.

Problem: the agreements

The device plugin compares two lists:

  • The latest agreement versions of the product. The app fills them from "agreements" in /api/v5/product.
  • The signed versions. The app fills them from userPluginAgreementList in /api/v1/checkAppAgreement.

The check passes only if both lists hold USER_AGREEMENT and PRIVACY_POLICY, and no signed version is lower than the latest one.

The route answered "agreements": [], so the check failed on every open. The plugin then took its privacy dialog path.

#207 added the empty agreements field and #209 added /api/v1/checkAppAgreement. This PR connects the two.

Change

  • The login answer has "region" in lower case, as the cloud sends it.
  • "country" is "DE" for the EU region, which fits the "countrycode": "49" that the server already sends. Other regions keep their upper-case region as the country.
  • /api/v1/getUrlByEmail and /api/v1/userInfo name the same country and dialing code as the login answer. All three take them from the new region_country() in shared/constants.py. Its table replaces the two dialing-code tables in server.py and routes/api/v1/user.py. A country from the cloud snapshot still wins in /api/v1/userInfo. The vacuum's /location route keeps its "EU".
  • New product_agreements() in routes/api/v1/agreement.py. It returns one entry per agreement type, with the same version that /api/v1/checkAppAgreement reports as signed, for example {"type": "PRIVACY_POLICY", "version": 1, "minorVersion": 0}.
  • /api/v5/product uses it for "agreements" instead of [].
  • tests/conftest.py: write_release_config takes a region option.

With a cloud import, the login answer comes from the snapshot, so the cloud's own region and country apply. This PR changes only the local answer.

A phone that is already logged in keeps its stored user without region, because /api/v1/userInfo does not send it. So after the update, log out of the app and back in once.

Home Assistant reads the region through python-roborock. There, only cn changes the behavior (in get_clean_routes), so EU and US servers behave as before. A CN server now gets the CN clean routes, as with the cloud.

Related

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
  • App: Android 4.60.06, patched for the local server
  • Server version / commit: the device test ran on e839839 of my fork's a307-plugin branch. That build is upstream main 32608dd plus the first two commits of 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, on upstream main 2069fc7.
  • Install method (Docker / Home Assistant add-on / other): built from source

What I did and what happened:

Before: the device plugin stayed on its map loading screen. Without the agreements, it failed its agreement check and took its privacy dialog path. Without the region, it looped in its country lookup, and the server got no request from it.

After the deploy, the plugin still hung at first, because the app keeps the login answer of its last login. I deleted the app's data and logged in again. Then the map loaded.

Tests:

  • New test_local_pin_login_names_the_region_and_country_of_the_config logs in without a cloud snapshot, for eu (region eu, country DE, countrycode 49) and for us (region us, country US, countrycode 1).
  • New test_url_and_user_info_routes_name_the_country_of_the_login_answer checks that getUrlByEmail and userInfo name the country and dialing code of the login answer, for eu and us. New test_user_info_prefers_the_country_of_the_cloud_snapshot checks that a snapshot country still wins.
  • test_product_entry_carries_rriotid_category_id_and_agreements now expects both agreement types.
  • New test_product_agreements_are_signed_in_plugin_agreements checks that for both types, the signed version of the device in /api/v1/checkAppAgreement is at least the latest version in /api/v5/product.
  • Full suite: uv run --extra dev pytest -q passes (508 tests).

Screenshots (required for any UI change)

No UI changes.

The device plugin starts with fetchCountryInfo. It gets countryCode and
serverCode from the app. The app takes them from the stored login
answer: "country" becomes RRUser.countryIso and "region" becomes
RRUser.region, which is the serverCode. If serverCode is empty, the
plugin reads areaServerMap[countryCode].code. No entry of that map has
a code, so the call throws. The catch block calls fetchCountryInfo
again at once, so the plugin loops forever and sends no request.

Without a cloud snapshot, the login answer had no "region", and its
"country" was "EU". So the a307 plugin never got to the agreement check
or the map.

Send "region" in lower case, as the cloud does, and send "DE" as the
country of the EU region. The EU cloud answers "region": "eu",
"country": "DE" and "countrycode": "49".
The device plugin checks the privacy agreements before it asks for the
map. It reads the latest versions of its product with
getProductAgreements. The app fills them from "agreements" in
/api/v5/product. It reads the signed versions with getPluginAgreements.
The app fills them from userPluginAgreementList in
/api/v1/checkAppAgreement. The check passes only if both lists hold
USER_AGREEMENT and PRIVACY_POLICY and no signed version is lower than
the latest one.

The route sent "agreements": [], so the check always failed. The plugin
then took its privacy dialog path instead of going on to
app_get_init_status and the map.

Send both agreement types with the version that /api/v1/checkAppAgreement
reports as signed. The entries use the cloud's shape, for example
{"type": "PRIVACY_POLICY", "version": 36, "minorVersion": 0} for the
a307.
The local login answer names "DE" as the country of the EU region, but
/api/v1/getUrlByEmail and /api/v1/userInfo still answered "EU". So one
account showed two countries. All three routes now take the country
from REGION_COUNTRY in shared/constants.py, and a country from the
cloud snapshot still wins in /api/v1/userInfo.
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 block the login geography and product agreement compatibility changes.

No open issues 🎉

What changed in this PR

This PR fixes two response mismatches that prevent the Android device plugin from loading maps against the local server: missing login geography and empty product agreement metadata.

Changes:

  • Adds lowercase login regions and maps EU app-facing country values to DE, while preserving cloud snapshot values and vacuum /location behavior.
  • Aligns product agreement versions with signed plugin agreements through the shared v4/v5 product response builder.
  • Adds regression coverage for login geography, country consistency, snapshot precedence, and agreement compatibility.
File Description
tests/​test_protocol_auth.py Tests regional login fields, country consistency, and snapshot precedence.
tests/​test_product_response.py Verifies required agreement types and compatible signed versions.
tests/​conftest.py Adds a region option to the release configuration helper.
src/​roborock_local_server/​server.py Adds region and mapped country fields to local login identities.
src/​roborock_local_server/​bundled_backend/​shared/​constants.py Defines the shared EU-to-DE country mapping.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​api/​v1/​user.py Applies consistent country defaults to discovery and user-info responses.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​api/​v1/​agreement.py Provides product agreement metadata using shared signed-version constants.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​api/​product_service.py Replaces empty product agreements with the shared metadata.

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:

  • Without region, the plugin loops.
    • It uses serverCode || areaServerMap[countryCode].code and calls itself again on any exception (tanos 0.js:479-507; refreshed Saros 20 Flow module_0.js:2476-2537).
    • areaServerMap has de but no eu, so "country":"EU" throws and DE resolves.
  • The app reads both fields. RRUser has region and maps JSON country to countryIso. The cloud sends region in lower case (python-roborock mock data).
  • Agreements: hasSignLastestPluginPrivacyAgreement needs both PRIVACY_POLICY and USER_AGREEMENT with signed version ≥ latest. The PR's entries pass, and shared devices are covered too.
  • Scope: no new routes and no auth changes. B01 bundles don't run the agreement check.

Unverifiable:

  • The native mapping from /api/v5/product agreements to getProductAgreements.
  • Where serverCode is derived.
  • What the EU cloud really sends as country.
  • iOS behaviour.

Conflicts:

  • #208: conflicts in product_service.py; keep both, as your body says.
  • #295: trivial conflict in constants.py; keep REGION_COUNTRY.
  • #288, #293 and #294 merge cleanly.

Nits:

  • The region-to-country logic is now in three places (server.py:71, routes/api/v1/user.py:14, server.py:602). Move the dialing-code table and one helper next to REGION_COUNTRY.
  • The comment at product_service.py:60 credits getProductAgreements, which the decompiled APK can't confirm.

Checks: all 508 tests pass.


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.

…lace

server.py and routes/api/v1/user.py each had a table of dialing codes
and a helper, and REGION_COUNTRY in shared.constants named the country.
One table in shared.constants now holds both, and region_country returns
them. The login, getUrlByEmail and userInfo answers use it, and a test
checks that all three name the same dialing code.
@Hoeze

Hoeze commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author
  • Region to country in three places: fixed in 5b4eae2. One table in shared/constants.py now holds the country and the dialing code of each region, next to the reason for DE, and region_country() returns both. The login answer in server.py, getUrlByEmail and userInfo all use it. The two old dialing-code tables were on main already, so this also removes those. The test of the three answers now checks the dialing code too.
  • The getProductAgreements comment at product_service.py:60: that line comes from fix(api): add rriotid, categoryId, category code and agreements to /api/v5/product #207 on main. This PR only adds the sentence about the empty list. Live, the plugin stayed on its map loading screen before this PR. With both agreements and the region, it requested the map and loaded it. That test changed both at once, so it does not confirm the native mapping from agreements to getProductAgreements.

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

What changed since the reviewed commit (d91aacb):

  • 5b4eae2 moves the region-to-country logic into one place, as the last review asked. REGION_COUNTRY now maps each region to (country, dialing code), and region_country() (shared/constants.py:138-149) serves the login answer (server.py:617), getUrlByEmail (routes/api/v1/user.py:38) and userInfo (user.py:70). Both old _REGION_COUNTRY_CODE tables and their helpers are gone, and nothing else still calls them. The outputs for us/cn/eu/ru and for unknown regions match the old code (unknown regions still fall back to dialing code "1"). The test at tests/test_protocol_auth.py:265 now checks the dialing code as well.
  • 8ece039 merges main (#179, #251, #253, #282, #288) with no conflicts. Against main, the diff is still limited to the eight files this PR names.

Claims re-checked:

  • Confirmed: the plugin loops when region is missing. fetchCountryInfo computes t.serverCode || areaServerMap[countryCode].code and calls itself again in its catch block (nonhermes/com.roborock.tanos/output/0.js:479-507). With region present, serverCode is never empty, so the country lookup isn't reached for us/cn/ru/sg either.
  • Confirmed: the app maps JSON country to RRUser.countryIso and keeps region (jadx/.../sdk/bean/RRUser.java:19-31). isCN() checks countrycode == "86" or countryIso == "CN" (RRUser.java:171-176), and both still hold for the CN region. python-roborock's UserData has region too (roborock/data/containers.py:232).
  • Confirmed: the agreement code hasn't changed since the last review. product_agreements() (routes/api/v1/agreement.py:42-52) and plugin_agreements() use the same types and versions. It is wired in at product_service.py:64.
  • Unverifiable: the native mapping from agreements to getProductAgreements, where serverCode comes from natively (serverCode doesn't appear in the APK's Java sources), iOS, and what the EU cloud really sends as country.

Concerns from the brief:

  • Existing users: the login answer is built fresh on each login, but phones already logged in keep a stored RRUser without region. userInfo doesn't send region, so those phones probably need to log out and back in.
  • Snapshot users: _protocol_login_identity (server.py:630-645) returns the cloud user_data. That data has the cloud's own region, so this PR doesn't change their path.
  • B01 and mower bundles: they don't run this agreement check (same finding as last time). Adding the field to their product entries is harmless.

Overlaps (git merge-tree):

  • main: merges cleanly.
  • #295: conflict in constants.py. #295 deletes MODEL_PRODUCT_ID_OVERRIDES, which sits next to REGION_COUNTRY. Drop the overrides and keep REGION_COUNTRY and region_country().
  • #208: two hunks in product_service.py. Keep both imports (product_agreements, card_spec_for_category), and keep "agreements": product_agreements() next to #208's productTags.

Nits:

  • In the PR body or the release notes, tell users who are already logged in to log out and back in on the phone. Otherwise the fix won't reach them.
  • region_country() (constants.py:149) gives an unknown region such as sg the dialing code "1". That behaviour existed before this PR, but now that the table is in one place, "SG": ("SG", "65") is a one-line addition if sg is meant to be supported.

Checks: uv run --extra dev pytest -q on 8ece039: 791 passed.


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

TY!

@Lash-L
Lash-L merged commit 86bb98c into Python-roborock:main Nov 28, 2026
3 checks passed
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