fix: always show charge energy for current and last session #414
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.
Fixes #295 and #413
Based on the information here, I realized that the logic to set the energy added to 0 when not charging was breaking energy calculations.
The actual energy added value is reset by tesla on it's own, so when we manually set 0, and then revert back to the tesla's value if charging starts again for the same charge session, it will cause the energy dashboard to incorrectly sum the deltas.
It appears that TOTAL_INCREASING is the right state class to use, as we don't expect the value to decrease substantially (a 10% allowance is built in). So if we just rely on the car's own charging state to reset appropriately, the energy dashboard should reflect usage correctly.
What this changes for users:
Test plan
Tested in dev container with a model 3:
energy_added sensor showing that it did not reset to zero when pausing (the blank area is "Unknown" from reloading while asleep)
The energy dashboard value matches the sensor (it did not double it, even after the "unknown" period)