Loadpoint: keep vehicle SoC when re-assigning the same default vehicle#31063
Draft
Alexxtheonly wants to merge 1 commit into
Draft
Loadpoint: keep vehicle SoC when re-assigning the same default vehicle#31063Alexxtheonly wants to merge 1 commit into
Alexxtheonly wants to merge 1 commit into
Conversation
setActiveVehicle always called unpublishVehicle, which zeroes vehicleSoc (and range/odometer) and publishes 0. vehicleDefaultOrDetect re-assigns the already-active default vehicle on every (re)connect to refresh the soc estimator for the new session (evcc-io#27359, evcc-io#27364), so unpublishVehicle ran even when the active vehicle did not change. For a vehicle whose SoC is known (e.g. teslamate via MQTT), this makes vehicleSoc/vehicleRange flap to 0 until the next successful soc read. It is most visible after an evcc restart mid-charge, where the synthesized reconnect path keeps re-assigning the default vehicle and the published SoC stays 0 while charging. Only reset the published vehicle data when the active vehicle actually changes (from != to). The soc estimator is still rebuilt unconditionally for v != nil, so the evcc-io#27359 fresh-estimator behaviour is preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
Does this refer to the restart? At restart, evcc simply does not know what was assigned before and doing so is hence correct. Seems I'm missing the actual root cause here. |
andig
reviewed
Jun 21, 2026
| lp.publish(keys.PhasesActive, lp.ActivePhases()) | ||
| lp.unpublishVehicle() | ||
|
|
||
| // only reset published vehicle data when the active vehicle actually changed. |
Member
There was a problem hiding this comment.
Can we keep comments to 2 lines please? Your AI ignores the agents.md?
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.
Problem
A loadpoint with a default
vehicle:whose SoC is known (e.g. ateslamatevehicle reading SoC over MQTT) publishesvehicleSoc = 0to/api/state(and messaging) while charging, even though the per-cyclevehicle soc: NN%debug log shows the correct value every cycle. It recovers after a clean physical connect (charger status A→B→C) but gets stuck at0after an evcc restart that happens mid-charge.vehicleRange/vehicleOdometerare zeroed the same way.Root cause
setActiveVehicle()callsunpublishVehicle()unconditionally at the end of every invocation, which setslp.vehicleSoc = 0and publishes0for soc/range/limit/odometer.vehicleDefaultOrDetect()re-assigns the already-active default vehicle on every reconnect (introduced in #27364 to fix the estimator gradient on reconnect, #27359):So when the active vehicle does not change,
unpublishVehicle()still wipes a perfectly valid SoC.publishSocAndRange()only repopulatesvehicleSocon a cycle where a SoC is actually read, so whenever a same-vehicle re-assign lands without an immediately-following successful read (e.g. the repeated reconnect/charger out of syncchurn after a mid-charge restart), the published value stays0.Fix
Only reset the published vehicle data when the active vehicle actually changes (
from != to). The soc estimator is still rebuilt unconditionally forv != nil(lines just above), so the #27359 fresh-estimator-on-reconnect behaviour is unchanged. Switching to a different vehicle — or to none on disconnect — still clears the stale data as before.This does not touch the vehicle-detection path: with a pinned default vehicle,
vehicleDefaultOrDetecttakes thedefaultVehicle != nilbranch and never runs detection.Test
Added
TestReassignActiveVehicleKeepsSoc, which sets a knownvehicleSoc, re-assigns the same active vehicle, and asserts the SoC is preserved — then asserts it is still cleared when the vehicle changes. It fails onmaster(expected 71, actual 0) and passes with the fix. Full./core/...suite passes;gofmt/go vet/modernizeclean.Reproduction
teslamatedefault vehicle (SoC via MQTT), actively charging./api/stateloadpoints[].vehicleSocstays0while the logs showvehicle soc: NN%every cycle.🤖 Generated with Claude Code