Skip to content

fix(inverter): restore calculated capacity sensor after restart - #5283

Merged
springfall2008 merged 2 commits into
springfall2008:mainfrom
Speshman:fix/soc-max-calculated-after-restart-5222
Sep 30, 2026
Merged

springfall2008 merged 2 commits into
springfall2008:mainfrom
Speshman:fix/soc-max-calculated-after-restart-5222

Conversation

@Speshman

Copy link
Copy Markdown
Contributor

Fixes #5222.

After a restart, battery_size_tracking() recovers today's measurement and trimmed mean from recorder history, but skips its only sensor-publishing branch. Re-publish soc_max_calculated from the recorded measurement only if the live entity is missing. A present entity is left alone, and the daily battery-size calculation is not rerun.

Extend the existing restart regression test to assert that the sensor returns with its state and history and is not re-published on subsequent cycles. Add a case where today's recorded measurement is None, preserving that failed day while restoring the sensor from earlier valid measurements.

Validation: ./run_all --test find_battery_size passed with an isolated empty secrets file; targeted whitespace, encoding, Ruff and Black hooks passed. The full quick run could not be validated in this environment because its secrets-loading test assumes no external Home Assistant secrets file, while this container exposes one. The all-hooks run also hit npm EALLOWGIT initializing markdownlint; those unavailable Node hooks were skipped in the targeted Python hook run.

@springfall2008 springfall2008 added the BOT_REVIEW Trigger an autotriage label Sep 28, 2026
@springfall2008

Copy link
Copy Markdown
Owner

Automated review failed to complete for this PR - see the triage bot's logs for details. The run exited cleanly but posted nothing, so the review step itself did not complete. Not retrying automatically; remove BOT_FAILED and re-add BOT_REVIEW to try again.

@springfall2008 springfall2008 added BOT_FAILED An automated triage/PR attempt failed; see the comment for details and removed BOT_REVIEW Trigger an autotriage labels Sep 28, 2026
@Speshman

Copy link
Copy Markdown
Contributor Author

Thanks for checking. Since the code-quality check passed and the review bot exited without posting, could you share the relevant redacted log lines or what prevented the review from being posted? That would help us decide whether a retry is worthwhile.

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated review from the triage bot (/code-review high), posted manually by a maintainer because the bot's own posting step did not run.

Reviewed at head 7217c0df. The fix works for the #5222 scenario. After an HA restart, the periodic update_states() wipes state_data, the elif republishes via set_state (which also refreshes state_data), and the next cycle skips, matching the tests' second-cycle guard. No neighbouring tests in the shared fixture are disturbed.

Findings 1 and 2 are narrow real defects. Findings 3 and 4 are test-coverage and efficiency cleanups. Nothing was found in the removed-behaviour, cross-file or conventions passes.

Comment thread apps/predbat/inverter.py Outdated
Comment thread apps/predbat/inverter.py Outdated
Comment thread apps/predbat/tests/test_find_battery_size.py
Comment thread apps/predbat/inverter.py Outdated
@springfall2008 springfall2008 removed the BOT_FAILED An automated triage/PR attempt failed; see the comment for details label Sep 28, 2026
@Speshman

Copy link
Copy Markdown
Contributor Author

Updated in a7d1246 for review points 1–3: the recovery path keeps the already-recorded planning mean (including all-None history), validates recorded history before calling the publisher so malformed entries cannot abort the inverter refresh, and tests that the None-today case does not republish on the next cycle. New regressions cover the all-None one-cycle scaling case and malformed history. With invalid history, the sensor is left missing rather than publishing corrupted data; planning still uses the recorded state.

On point 4: the duplicate reads happen only on the missing-entity recovery cycle. Eliminating both cleanly would require passing cached state/history through or restructuring the publishing helper, so I kept this correctness fix narrow. Happy to consider a separate efficiency follow-up if useful.

The isolated find_battery_size suite, applicable Python hooks and CSpell pass locally. The full quick suite is not validated in this environment because its secrets-loading test assumes no external Home Assistant secrets file.

gcoan pushed a commit to gcoan/batpred that referenced this pull request Sep 28, 2026
…-review's print fallback

/code-review --comment prefers mcp__github_inline_comment__create_inline_comment and,
when that tool is missing, says "fall back to gh api ... or print the findings instead".
The bot never loads that tool (--strict-mcp-config), so every review lands on that
sentence. PR springfall2008#5283's run took the print branch without attempting gh api at all, so
nothing was denied and the existing "report a denial, don't print" rule never applied.
The review was lost and the PR was marked BOT_FAILED.

GH_API_ENDPOINT_FIRST_PROMPT now names the tool as absent and makes gh api the required
path, allowing printing only after a gh api call has actually been denied.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@springfall2008
springfall2008 merged commit d7c1a10 into springfall2008:main Sep 30, 2026
2 checks passed
springfall2008 added a commit that referenced this pull request Oct 2, 2026
…0-01

docs(debug-journal): fold in the 2026-10-01 queue slice (9 candidates); mark GH#5313 fixed by PR #5315, GH#5136 by PR #5293, GH#5222 by PR #5283, the iog-slot-io-adjusted row by PR #5304, GH#5068 reworked by PRs #5309/#5314; add the dynamic-load car cancel row and the GH#2649/#5302/#5324 findings
gcoan pushed a commit to gcoan/batpred that referenced this pull request Oct 3, 2026
…); mark GH#5313 fixed by PR springfall2008#5315, GH#5136 by PR springfall2008#5293, GH#5222 by PR springfall2008#5283, the iog-slot-io-adjusted row by PR springfall2008#5304, GH#5068 reworked by PRs springfall2008#5309/springfall2008#5314; add the dynamic-load car cancel row and the GH#2649/springfall2008#5302/springfall2008#5324 findings

Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

sensor.predbat_soc_max_calculated disappears after an HA restart until the next midnight

2 participants