Skip to content

Make no charge of a plug-in hybrid's engine, and simulate one - #180

Merged
vcanuel merged 3 commits into
mainfrom
feat/plugin-hybrids
Oct 29, 2026
Merged

vcanuel merged 3 commits into
mainfrom
feat/plugin-hybrids

Conversation

@vcanuel

@vcanuel vcanuel commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

A first step of #165, which it does not close: the catalog's plug-in hybrid variants, the fuel of a trip and the documentation come next.

Two real Volvo V60 plug-in hybrids (2021 and 2027) were read for a week. Their charges on a plug come out right already, but their engine also raises the SoC while driving: holding an empty battery a point up and down, or in charge mode. Driven between two parked readings, such a rise would have made up a charge, with a cost.

Changes

  • core.Snapshot.Powertrain (electric, plugin_hybrid, other) replaces BatteryElectric, which stays as a method. Volvo's fuelType names a plug-in hybrid by its fuels joined by a slash (PETROL/ELECTRIC, as both V60s answer). Nothing it reads changes yet: the catalog still recognizes electric variants only.
  • Derivation: for a plug-in hybrid, a SoC rise read parked is a reconstructed charge only when the reading that shows it says the cable connected (detector.onPlug). The odometer would tell whether it drove, but parked it is read once an hour. A charge seen on its plug is unchanged, and so is an electric vehicle, or one whose powertrain is not read yet.
  • Simulator: a Volvo scenario's powertrain: plugin_hybrid (details PETROL/ELECTRIC, an empty battery held at holdSoc, a drive's engineChargeKWhPer100km for a charge mode, its rate an assumption; no fuel yet), the profile v60-phev-like, and scenarios/v60-phev.yaml.
  • AGENTS.md: the rule, and the simulated hybrid.

How it was tested

  • TestHybridReconstructedCharges (core): the cable connected, disconnected, not reported, connected only before; an electric car; the powertrain read after the rise; a charge mode on a trip seen; charge sustain. Each case in a rebuild and incrementally, with and without the vehicle's timestamps. The three that must refuse a charge failed without the rule.

  • TestSimulatedPlugInHybrid (derive): the scenario through the simulator, the collector and the derivation. One charge on the socket, the charge-mode trip revealed by the odometer, no charge made up; read as an electric car's, the same responses make one, so the scenario keeps its point. Without the rule, it fails with a made-up charge.

  • TestRealPlugInHybrids derives the two real V60s' responses and finds what production derived (20 and 8 trips, 5 and 1 charges, none made up). These responses are users' own: they stay out of the repository, and the test is skipped unless RUNSTEN_V60_FIXTURES names them.

  • Unit tests of the simulated vehicle (charge sustain, charge mode), of the scenarios' checks and of the details' fuelType.

  • task unit passes: task unit-go (lint, tests, govulncheck, build); unit-web not run, nothing of the front end nor of the API's contract changed

  • The API's diff (api/openapi.yaml, internal/api/testdata/) is intended, or there is none: none

  • Texts in English, French and Swedish, if the interface changed: it did not

  • No real VIN, token, API key or position, fixtures included

task integration and task system were not run locally: no migration, no change of the store, of Compose or of the images.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added plug-in-hybrid support, including configurable battery charge-sustain behavior and engine-assisted charging during drives.
    • Added a V60 plug-in-hybrid simulation scenario with driving, engine charging, and AC charging.
    • Vehicle details now distinguish plug-in hybrids from fully electric vehicles.
  • Bug Fixes
    • For plug-in hybrids, battery-charge increases are recognized as charging only when the vehicle is parked and connected.
  • Documentation
    • Added guidance on plug-in-hybrid scenarios and charge detection.

vcanuel and others added 3 commits October 29, 2026 21:58
A vehicle's powertrain replaces whether it runs on its battery alone:
electric, plug-in hybrid or other. Volvo's fuelType names a plug-in
hybrid by its fuels joined by a slash, PETROL/ELECTRIC as two real V60s
answer; a list holding ELECTRIC is taken for one. Nothing it reads
changes yet: the catalog still recognizes the electric ones only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A plug-in hybrid's engine raises the SoC while driving, in charge mode
or holding an empty battery: driven between two parked readings, such a
rise made up a charge, with a cost. For a plug-in hybrid, a rise read
parked is now a reconstructed charge only when the reading that shows it
says the cable connected; the odometer, read once an hour parked, would
tell too late. A charge seen on its plug is unchanged, and so is an
electric vehicle, or one whose powertrain is not read yet. A test derives
two real V60s' responses, kept out of the repository, when
RUNSTEN_V60_FIXTURES names them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Volvo scenario's powertrain may be plugin_hybrid: its details tell
PETROL/ELECTRIC, its engine holds an empty battery a point up and down,
as a real V60 did over 41 km, and a drive may have it charge the battery
(engineChargeKWhPer100km, its rate an assumption). Its fuel is not
simulated yet. scenarios/v60-phev.yaml drives in charge mode between two
parked readings: derived end to end, it makes no charge of it, where an
electric car's reading would.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

The change adds powertrain classification for plug-in hybrids, requires a connected cable for their reconstructed SoC-rise charges, and adds plug-in-hybrid behavior to the simulator. It also adds a V60 scenario and tests for the new behavior.

Changes: Plug-in hybrid support

Layer / File(s) Summary
Powertrain model and classification
internal/core/snapshot.go, internal/volvo/normalize.go, internal/polestar/*, internal/tesla/*, internal/api/*, cmd/runsten-collector/*, internal/core/*
Snapshots now represent powertrains as electric, plug-in hybrid, or other. Volvo fuel types map to these categories. Normalizers, API and collector code, and test fixtures use the updated representation.
Plug-in-hybrid charge reconstruction
internal/core/charge.go, internal/core/derive_test.go, internal/derive/hybrid_test.go, AGENTS.md
For a plug-in hybrid, a reconstructed SoC-rise charge requires the rise reading to report a connected cable. Tests cover cable states, trip and charge-sustain cases, incremental derivation, and real-vehicle fixtures.
Simulator behavior and V60 scenario
internal/simulator/scenario/*, internal/simulator/vehicle/*, internal/simulator/volvoapi/*, scenarios/v60-phev.yaml, AGENTS.md
Scenario configuration supports plug-in-hybrid powertrains, hold SoC, and engine charging during drives. The simulator applies hybrid charge-sustain and engine-charge behavior. Volvo details report PETROL/ELECTRIC, and the V60 scenario exercises the configuration.

Possibly related issues

  • Issue 165 asks for plug-in-hybrid support. This change adds powertrain identification and cable-aware charge detection, which address part of that objective. The issue description says catalog variants and trip fuel remain open.

Priority: Normal

Merge Risk: Minimal · up to 0357f

The plug-in-hybrid behavior is covered by the supplied implementation and tests, with no identified issue requiring a fix before merge. Run the normal checks before merging.

Security architecture risk: Low · up to 0357f

The change makes charging estimates more conservative for identified plug-in hybrids without adding vehicle-control privileges. No introduced security defect was established, but incomplete vehicle details and unconfirmed deployment exposure limit confidence.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The security-relevant outcome in the inspected production flow is the integrity of charging and energy records for the vehicle being derived. Classification and telemetry influence those records, but the change does not add a new account selector, credential source or vehicle-command capability along that flow.

Trust Boundaries and Controls

  • observed — The simulator continues to map reports by configured VIN within one simulated account. The changed details renderer consumes modeled powertrain state, while issuer setup, middleware routing and explicit command refusals remain separate and unchanged in the inspected comparison.

Resilience and Maintainability Implications

  • inferred — The new integrity safeguard depends on currently known hybrid metadata. A valid details response lacking readable fuelType can clear a previously known classification, restoring permissive SoC-only reconstruction; late metadata also does not retroactively remove an existing charge. These remain limitations of the safeguard, not demonstrated PR regressions, because the base permitted the same rises without hybrid gating.
Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title "Make no charge of a plug-in hybrid's engine, and simulate one" is imperative and describes the main change: the derivation rule that stops reconstructing charges from engine-driven SoC rise…
Description check Passed The description follows the repository template: it explains what changes and why, references related issue #165 with a non-closing note, lists the changes, and includes a How it was tested section wi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Make no charge of a plug-in hybrid's engine, and simulate one" is imperative and describes the main change: the derivation rule that stops reconstructing charges from engine-driven SoC rises for plug-in hybrids, and the new simulated plug-in hybrid scenario. It is specific to the changeset, though it is phrased with an unusual construction and does not follow the short "Add/Fix" style exactly. The title is related to the changeset and is not vague, so it passes.

Full details: Description check

Explanation

The description follows the repository template: it explains what changes and why, references related issue #165 with a non-closing note, lists the changes, and includes a How it was tested section with the required checklist items. The template's "Closes #" line is replaced by an explicit statement that the PR does not close #165, which is acceptable. The checklist items are marked, and the author explains why task integration and task system were not run. The description is mostly complete and specific.

Comment @coderabbitai help to get the list of available commands.

@vcanuel
vcanuel merged commit 8f9eeea into main Oct 29, 2026
8 checks passed
@vcanuel vcanuel mentioned this pull request Oct 30, 2026
5 tasks done
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