Loadpoint: update odometer on disconnect#30361
Merged
Merged
Conversation
Read the vehicle odometer again at disconnect and persist it into the session. Many vehicles only update their mileage with a delay, so the value captured at connect is often stale while the value after a completed charge is current.
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The test mutates the global
serverdb.Instancewithout restoring it, which can cause cross-test interference; consider saving the previous value and restoring it viat.Cleanup.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The test mutates the global `serverdb.Instance` without restoring it, which can cause cross-test interference; consider saving the previous value and restoring it via `t.Cleanup`.
## Individual Comments
### Comment 1
<location path="core/loadpoint_vehicle_test.go" line_range="448-456" />
<code_context>
+ var err error
</code_context>
<issue_to_address>
**suggestion (testing):** Reset or isolate the global serverdb.Instance to prevent cross-test interference.
Assigning to the package-level `serverdb.Instance` can leak state into other tests. Please either restore it to its previous value at the end of this test (e.g., via defer) or introduce a helper that creates an isolated in-memory DB per test and resets the global afterward to avoid order-dependent test failures.
```suggestion
func TestOdometerOnDisconnect(t *testing.T) {
prevInstance := serverdb.Instance
dbInstance, err := serverdb.New("sqlite", ":memory:")
require.NoError(t, err)
serverdb.Instance = dbInstance
defer func() {
serverdb.Instance = prevInstance
}()
db, err := session.NewStore("foo", serverdb.Instance)
require.NoError(t, err)
ctrl := gomock.NewController(t)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
andig
commented
May 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #30225, analogous to #29350
Re-read the vehicle odometer at disconnect and persist it into the session. Many vehicles (e.g. Skoda Enyaq) only update their mileage with a delay, so the value captured at connect is often stale, while the value after a completed charge is current. The charge-stop handler resets the API cache before disconnect, so the disconnect read returns a fresh value.
evVehicleDisconnectHandlerbefore the session is cleared