Fixes for battery size calc#3932
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts battery capacity/scaling behavior by caching failed battery-size calculations and wiring Fox/SolaX battery SOH sensors into automatic configuration.
Changes:
- Stores
Nonehistory entries for failed battery-size calculations and excludes them from capacity averaging. - Publishes Fox and SolaX battery SOH scaling sensors and auto-configures
battery_scaling. - Adds tests covering SOH publishing/configuration and failed battery-size tracking.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
apps/predbat/inverter.py |
Updates calculated battery-size history handling for failed measurements. |
apps/predbat/solax.py |
Adds SolaX SOH sensors and automatic battery_scaling configuration. |
apps/predbat/fox.py |
Adds Fox SOH sensor publishing and automatic battery_scaling configuration. |
apps/predbat/tests/test_find_battery_size.py |
Adds tests for failed battery-size history and None handling. |
apps/predbat/tests/test_solax.py |
Adds SolaX SOH publishing and auto-config assertions. |
apps/predbat/tests/test_fox_api.py |
Adds Fox SOH publishing and auto-config assertions. |
Comments suppressed due to low confidence (2)
apps/predbat/tests/test_find_battery_size.py:824
- This pre-populates the guard key with
date.today()whilebattery_size_tracking()checksself.base.now_utc.date(). If the system date differs from Predbat's configured date, the guard will not match and the test will incorrectly callfind_battery_size.
today_key = str(date.today())
# Pre-populate history with today's key already set to None (simulating a previous failed run)
my_predbat.ha_interface.dummy_items[sensor_name] = {"state": "unknown", "history": {today_key: None}}
apps/predbat/tests/test_find_battery_size.py:931
- The fixture builds history dates from the host's
date.today()instead of Predbat'snow_utc.date(). When those dates differ, one of these “previous day” entries can collide with the production code's today key and be overwritten, changing the sample set and making the expected trimmed mean nondeterministic.
from datetime import date, timedelta as td
# 2 valid days + 1 None day; calling with a new valid value → 3 real values total
# values: 9.0, 9.5, 9.2 → sorted [9.0, 9.2, 9.5] → trimmed mean = 9.2
existing_history = {
str(date.today() - td(days=3)): 9.0,
str(date.today() - td(days=2)): None, # failed day
str(date.today() - td(days=1)): 9.5,
…into fix/battery_size
…into fix/battery_size
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.
No description provided.