Fix incorrect SoC when battery_scaling_auto is enabled#3974
Merged
springfall2008 merged 1 commit intoMay 30, 2026
Conversation
Preserve manual DoD/usable config when battery_scaling_auto is enabled by introducing battery_scaling_config and clamping auto-scaling to [config*0.8, config]. Update Inverter to set battery_scaling from the computed value and to default battery_scaling to 1.0 when no nominal capacity is configured. Add/adjust unit tests: helper _clamped_auto_scaling, assert battery_scaling is updated in existing auto-scaling tests, add test_battery_scaling_auto_preserves_configured_scaling to ensure measured degradation below configured DoD is applied, and wire the new test into the test runner.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a battery degradation auto-scaling inconsistency that could cause Predbat’s displayed SoC to drift from the inverter’s real SoC when battery_scaling_auto is enabled alongside a configured battery_scaling baseline (e.g., DoD correction like 0.8). It does this by treating the configured battery_scaling as an upper bound and only allowing auto-scaling to reduce from that baseline.
Changes:
- Introduces a per-inverter baseline (
battery_scaling_config) captured from the configuredbattery_scalingvalue. - Updates
battery_size_tracking()to clamp auto-scaling to[0.8 * configured_scaling, configured_scaling]and to updateself.battery_scalingalongsidesoc_max. - Extends the battery sizing tests to validate both
soc_maxandbattery_scaling, including a new case ensuring configured scaling is preserved as an upper bound.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/predbat/inverter.py | Stores configured scaling baseline and clamps battery_scaling_auto relative to it while updating runtime battery_scaling consistently. |
| apps/predbat/tests/test_find_battery_size.py | Updates expected scaling calculations and adds coverage ensuring auto-scaling respects configured battery_scaling as the cap. |
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.
Fixed battery degradation auto-scaling so it respects the configured battery_scaling baseline.
Previously, battery_scaling_auto could update soc_max without keeping the effective runtime battery scale consistent. This could make Predbat’s displayed SoC diverge from the real inverter SoC, especially on systems using battery_scaling for DoD correction, such as 0.8.
The change now treats the configured per-inverter battery_scaling value as the upper bound, and only allows auto degradation to reduce from that baseline. For example, battery_scaling: 0.9 can auto-adjust within 0.72-0.9, while battery_scaling: 0.8 can adjust within 0.64-0.8. This preserves manual DoD/SOH correction while still allowing measured battery degradation to be applied consistently to both soc_max and shown SoC.
#3940 - fixes this issue.