Skip to content

Loadpoint: update odometer on disconnect#30361

Merged
andig merged 3 commits into
masterfrom
feat/odometer-on-disconnect
May 31, 2026
Merged

Loadpoint: update odometer on disconnect#30361
andig merged 3 commits into
masterfrom
feat/odometer-on-disconnect

Conversation

@andig
Copy link
Copy Markdown
Member

@andig andig commented May 31, 2026

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.

  • read odometer in evVehicleDisconnectHandler before the session is cleared
  • the connect-time read is kept so the live UI still shows a value immediately

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.
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread core/loadpoint_vehicle_test.go Outdated
Comment thread core/loadpoint.go Outdated
@andig andig added the enhancement New feature or request label May 31, 2026
@andig andig enabled auto-merge (squash) May 31, 2026 09:02
@andig andig merged commit fd94f8a into master May 31, 2026
13 checks passed
@andig andig deleted the feat/odometer-on-disconnect branch May 31, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant