Skip to content

Fix battery degradation calc when battery is already scaled#3949

Merged
springfall2008 merged 8 commits into
mainfrom
fix/battery_size_deg
May 25, 2026
Merged

Fix battery degradation calc when battery is already scaled#3949
springfall2008 merged 8 commits into
mainfrom
fix/battery_size_deg

Conversation

@springfall2008
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 22, 2026 07:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes battery-size/degradation calculations when battery_scaling is already applied (e.g., depth-of-discharge limits), ensuring find_battery_size() estimates usable capacity rather than accidentally returning nominal capacity. It also adds regression tests around scaling behavior and failure paths.

Changes:

  • Correct Inverter initialization so nominal_capacity remains unscaled while soc_max reflects scaled (usable) capacity.
  • Fix find_battery_size() to stop applying battery_scaling to SoC percentage history inputs.
  • Add/extend unit tests to cover scaling and “find_battery_size failed” behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
apps/predbat/inverter.py Fix nominal vs usable capacity handling; adjust find_battery_size SoC% scaling; add a new dashboard attribute/log detail.
apps/predbat/tests/test_find_battery_size.py Add regression test for battery_scaling < 1.0 and assert soc_max doesn’t change on failed sizing when auto-scaling is off.
Comments suppressed due to low confidence (1)

apps/predbat/tests/test_find_battery_size.py:1103

  • This blank line contains whitespace only. Please remove the spaces to avoid trailing-whitespace lint failures and keep diffs clean.
    failed |= test_battery_size_tracking_none_stored_on_failure(my_predbat)
    if failed:
        return failed

Comment thread apps/predbat/inverter.py Outdated
found_size_str = "{:.2f} kWh".format(found_size) if found_size is not None else "None"
degradation = (self.nominal_capacity - trimmed_mean) / self.nominal_capacity if self.nominal_capacity > 0 else 0
self.log("Inverter {} battery size tracking: found_size {}, history {}, trimmed_mean {:.2f} kWh, degradation {:.2%}".format(self.id, found_size_str, history, trimmed_mean, degradation))
self.log("Inverter {} battery size tracking: found_size {}, history {}, trimmed_mean {:.2f} kWh, degradation {:.2%} configured degradation {:.2f}".format(self.id, found_size_str, history, trimmed_mean, degradation, self.battery_scaling))
Comment thread apps/predbat/inverter.py
Comment thread apps/predbat/tests/test_find_battery_size.py
@springfall2008
Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

Copy link
Copy Markdown
Contributor

Copilot AI commented May 22, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved. The conflict was in test_find_battery_size.py where our branch had replaced test_find_battery_size_soc_kw_unavailable with test_find_battery_size_with_scaling, while main had added test_find_battery_size_soc_kw_unavailable as a new test. The resolution keeps both functions — test_find_battery_size_with_scaling and test_find_battery_size_soc_kw_unavailable — and both tests pass.

@springfall2008 springfall2008 merged commit 2b8ecab into main May 25, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/battery_size_deg branch May 25, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants