Skip to content

Fixes for battery size calc#3932

Merged
springfall2008 merged 10 commits into
mainfrom
fix/battery_size
May 16, 2026
Merged

Fixes for battery size calc#3932
springfall2008 merged 10 commits into
mainfrom
fix/battery_size

Conversation

@springfall2008
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 16, 2026 19:03
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 adjusts battery capacity/scaling behavior by caching failed battery-size calculations and wiring Fox/SolaX battery SOH sensors into automatic configuration.

Changes:

  • Stores None history 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() while battery_size_tracking() checks self.base.now_utc.date(). If the system date differs from Predbat's configured date, the guard will not match and the test will incorrectly call find_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's now_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,

Comment thread apps/predbat/solax.py Outdated
Comment thread apps/predbat/tests/test_find_battery_size.py Outdated
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.

2 participants