Skip to content

Read each vehicle through its connection's provider - #82

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

vcanuel merged 1 commit into
mainfrom
polestar-collector

Conversation

@vcanuel

@vcanuel vcanuel commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Part of #52 (step 3: schema and collector by provider). It does not close the issue: the API, the Connection page and a check on a real car remain.

What changes

  • Migration 0023: a Polestar connection (provider polestar, one per account beside the Volvo ID) holds the owner's Data Portal credential, one sealed JSON value bound to the account and its column; in plaintext its last four characters and when it was set. credential_refused_at, vehicles.unshared_at, the new failure kinds (credential_refused, unshared, not_granted), the polestar API in api_calls; runsten_poll_targets() gives the provider. The export omits the credential.
  • Collector by provider: every source is described the same way (endpoints, pace per mode, budget API, readings at the end of a trip or charge). Volvo is read as before; a Source (AddSource) reads the others. For the Polestar Data Portal (internal/collector/polestarsource, the client adapted): token asked at the first call, kept until it expires, asked again once on a 401; the reactions of ADR 0038 §3; 10,000 calls a day per credential. The collector imports neither polestar nor its formats (depguard, archtest).
  • Neutral endpoint type: Snapshot, Call, Failure and VehicleState use collector.Endpoint. The Volvo tests of the collector change by type conversions only: no scenario, figure or assertion changed.
  • derive.Sources: one normalizer per source, chosen by core.Kind.Source, in runsten-collector and runsten-api.
  • A model without a family: the Polestar normalizer tells the brand; catalog.MatchBrand, Recognize and Chosen accept the brand's variants when the family is unknown, and the choice sets it. The derivation's net capacity follows. The API (offered) is left for the next step.
  • RUNSTEN_POLESTAR_BASE_URL in runsten-collector.

Tests

  • End to end on polestar2: three trips, a DC and an AC charge, the incremental derivation equal to a rebuild; a fleet of a Volvo and a Polestar under one account.
  • The collector's Source: paces, token lifecycle, each refusal, quota per credential.
  • Store (PostgreSQL): credential round trip, checks, isolation.
  • task unit-go and task integration pass locally.

Left for the next step

The API's enumeration of failure kinds, its vehicle list (which reads a Volvo connection's columns), offering the brand's variants, sim.env and the Taskfile. The catalog has no sourced net capacity for ps2-lr-single-2024, the demonstration car's variant.

🤖 Generated with Claude Code

The collector read the Volvo Cars API only. A connection now names its
provider, and the collector reads each vehicle through it: the Volvo
API as before, or a Source the binary adds, the Polestar Data Portal
first, read with the owner's credential.

Migration 0023: connections.provider accepts polestar, one per account
beside the Volvo ID. Its credential (client ID, secret and account ID)
is one JSON value sealed bound to the account and to its column; in
plaintext only its last four characters and when it was set. The
Portal's refusal of it is dated (credential_refused_at), and so is a
vehicle no longer shared with it (vehicles.unshared_at), which listing
it again clears. runsten_poll_targets gives the provider; api_calls
and collector_status take the Portal's API and its kinds of failure.
The export leaves the credential out.

The collector describes every source the same way: its name, its
endpoints with their pace in each mode and the API each call counts
on, those read at once when a trip or a charge ends. The endpoints of
its public types become a neutral collector.Endpoint, so the Volvo
tests change by type conversions only. A Source's access token is
asked for at the first call due, kept in memory until it expires,
asked again once on a 401. A refused credential marks the connection,
an unshared VIN the vehicle; a domain not granted is left out a day
and told, one the car does not give an hour; a 429 pauses the
connection. The Portal's 10,000 calls a day count per credential.
internal/collector/polestarsource adapts the Polestar client, so that
the collector imports neither it nor its formats.

derive.Sources gives the derivation one normalizer per source, chosen
by the kind's source. A Polestar's family is unknown: the normalizer
tells its brand, and the catalog matches and accepts a choice among
the brand's variants, which sets the family, so that the energies rest
on the net capacity of the variant chosen.

Tested end to end on the polestar2 scenario (three trips, a DC and an
AC charge, the incremental derivation equal to a rebuild) and on a
fleet of a Volvo and a Polestar; the store's credential, its checks
and its isolation against PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vcanuel
vcanuel merged commit f2c9dda 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