Skip to content

Simulate the Polestar Data Portal's M2M API - #80

Merged
vcanuel merged 1 commit into
mainfrom
polestar-source
Oct 20, 2026
Merged

vcanuel merged 1 commit into
mainfrom
polestar-source

Conversation

@vcanuel

@vcanuel vcanuel commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

A Polestar is read through the Polestar Data Portal (EU Data Act), with a credential its owner creates in the portal, not through the Volvo Cars API. This adds that API to the simulator, so the Polestar source can be built and tested without a car. Nothing in Runsten reads it yet: the client, the collector and the Connection page come next.

What it does

  • internal/simulator/polestarapi: the M2M API under its real base path, /eu-north-1/data-portal/m2m/.
    • POST /token takes clientId and clientSecret, as JSON or a form, without grant_type, and returns a token valid for one hour.
    • GET /v1/vehicles and the domains a logger reads: battery, odometer, location, availability and target-soc. The other domains answer DATA_NOT_AVAILABLE.
    • Every /v1 call needs the x-client-id header. The errors are the ones observed: VALIDATION_INVALID_PARAMETER, AUTHZ_CLIENT_ID_MISMATCH and AUTHZ_VIN_UNAUTHORIZED.
    • Limits per credential: 10,000 calls a day, 100 a minute. The credential's 90-day lifetime is off by default.
  • Scenarios take brand: polestar. Each brand is served on its own API, so a Volvo and a Polestar can run together.
  • scenarios/polestar2.yaml is the demonstration car: a Polestar 2 of 2024, with a commute, a DC charge and an AC charge.
  • testdata/polestar-data-portal/ holds real responses of a parked Polestar 2, published under the MIT licence by polestar-mcp. The tests compare the simulated shapes against them.

Assumptions

What the published responses don't show is a named, configurable assumption:

  • A parked car uploads its battery and availability every 10 minutes (SIM_POLESTAR_PARKED_UPLOAD). It reports ABANDONED one hour after its last trip or charge.
  • The position updates only at the end of a trip. Whether the car uploads it while driving is unknown, and no published response was taken during a drive.
  • The bodies of a 401 on /v1 and of a 429 are guesses. Neither has been published.

Checks

  • task unit-go passes: format, lint, the tests without PostgreSQL, govulncheck and the build.
  • Ran the simulator with commute and polestar2 together at ×600 and read the Polestar's domains over a simulated day. Odometer, SoC and usage mode change as the scenario says.

🤖 Generated with Claude Code

A Polestar does not go through the Volvo Cars API: its owner reads it
through the Polestar Data Portal (EU Data Act), with a credential created
in the portal. Nothing in Runsten can be built or tested against it
without a car, so the simulator now serves it, as it serves Volvo's.

A scenario of brand polestar is served under the real base path
(/eu-north-1/data-portal/m2m/): POST /token with the credential's client
ID and secret, then /v1/vehicles and the domains a logger reads (battery,
odometer, location, availability, target-soc), with the account in the
x-client-id header. The other domains answer DATA_NOT_AVAILABLE, as for a
car that does not upload them. Tokens live an hour; calls are limited per
credential (10,000 a day, 100 a minute); the credential's 90 days can be
switched on.

The shapes follow real responses of a parked Polestar 2, published under
the MIT licence by polestar-mcp and copied into
testdata/polestar-data-portal, which the tests compare against. What is
unknown is a named assumption: a parked car uploads its battery and
availability every 10 minutes and reports itself ABANDONED after an hour;
the position is the one of the end of the last trip.

scenarios/polestar2.yaml is the demonstration car: a Polestar 2 of 2024,
a commute, a DC charge and an AC charge. It runs alone or beside Volvo
scenarios, each brand on its own API. No part of Runsten reads it yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vcanuel
vcanuel merged commit 89e49c9 into main Oct 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant