fix: price-change fallback trigger no longer goes dead at a zero price#66
Merged
Conversation
6eeb4d8 to
e2357b6
Compare
The fallback threshold check in _handle_price_change skipped entirely when the previous price was exactly 0 (a free hour): the relative change is undefined there. Worse, _last_price was never updated inside the skipped branch, so once a 0 was stored the fallback path stayed disabled until a period boundary. A zero previous price now uses an absolute threshold (PRICE_CHANGE_REOPTIMIZE_ABS_EUR, 0.01 EUR/kWh) and _last_price is always updated. https://claude.ai/code/session_01ViddzhUiQT1rMibFjc2pn6
e2357b6 to
45fcaad
Compare
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.
Problem
The fallback threshold check in
_handle_price_change(used for sensors without timestamp attributes) was guarded byself._last_price != 0. At a price of exactly 0 (free hour) the relative change is undefined, so the whole branch was skipped — including the_last_price = new_priceupdate. Once a 0 was stored, the fallback trigger stayed permanently disabled until a period-boundary event happened to revive it.Fix
PRICE_CHANGE_REOPTIMIZE_ABS_EUR(0.01 €/kWh, new constant inconst.py)_last_priceis always updated in the fallback branch, so the trigger can never get stuckTests
_last_pricehttps://claude.ai/code/session_01ViddzhUiQT1rMibFjc2pn6
Generated by Claude Code