fix: fill full span of mixed-granularity evcc price entries - #406
Merged
Conversation
evcc sometimes returns hourly-width rate entries for prices further out in the forecast horizon while nearer-term prices are 15-min slots. _get_prices_native() only wrote the price at the entry's start index, leaving the remaining 15-min slots of an hourly entry missing from the returned dict. core.py assumes a contiguous price dict and crashed with an uncaught KeyError when it hit the gap, taking down the whole process. Use each rate entry's start/end to fill every 15-min slot it actually covers. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the evcc dynamic tariff provider when evcc returns mixed-granularity rate entries (e.g., hourly-width entries alongside 15-minute entries), by filling the full 15-minute span covered by each entry so downstream consumers see a contiguous index sequence.
Changes:
- Update
Evcc._get_prices_native()to use each rate entry’sstart/endspan and populate all covered 15-minute slots. - Strengthen the mixed-granularity unit test to assert that hourly entries fill all four quarter-hour indices and that the produced index range has no gaps.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/batcontrol/dynamictariff/evcc.py |
Fill all 15-min slots spanned by a rate entry (using start/end) to prevent gaps in the returned price dict. |
tests/batcontrol/dynamictariff/test_evcc.py |
Extend test assertions to verify hourly entries fill all quarters and the resulting index sequence is contiguous. |
Address Copilot review feedback on PR #406: round() could undercount the number of 15-min slots an evcc rate entry covers when its duration isn't an exact multiple of 900 seconds (timestamp rounding, DST transitions), silently recreating the gap this fix set out to remove. Use math.ceil() instead so every touched slot is always filled. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
Evcc._get_prices_native()only wrote the price into the single 15-min index matching the entry's start time, leaving the remaining quarters of an hourly entry missing from the returned dict.core.py._run_once()assumes a contiguousprice_dict(for h in range(fc_period + 1): prices[h] = round(price_dict[h], ...)), and that loop is not covered by the surrounding exception handler. Hitting the gap raised an uncaughtKeyError, crashing the whole batcontrol daemon (see attachedstartup.txttraceback that triggered this fix).start/endto compute how many 15-min slots it spans, and fill all of them with that entry's price instead of just the first one.Test plan
uv run pytest tests/batcontrol/dynamictariff/test_evcc.py -q— 9 passed, including strengthenedtest_mixed_granularity_priceswhich now asserts the previously-missing quarters are filled and there are no gaps in the index range.uv run pytest tests/ -q— full suite, 794 passed.uv run pylint src/batcontrol/dynamictariff/evcc.py— 10.00/10.🤖 Generated with Claude Code