Skip to content

fix: price-change fallback trigger no longer goes dead at a zero price#66

Merged
bvweerd merged 1 commit into
devfrom
claude/fix-13-zero-price-fallback
Jun 12, 2026
Merged

fix: price-change fallback trigger no longer goes dead at a zero price#66
bvweerd merged 1 commit into
devfrom
claude/fix-13-zero-price-fallback

Conversation

@bvweerd

@bvweerd bvweerd commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Problem

The fallback threshold check in _handle_price_change (used for sensors without timestamp attributes) was guarded by self._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_price update. Once a 0 was stored, the fallback trigger stayed permanently disabled until a period-boundary event happened to revive it.

Fix

  • A zero previous price now uses an absolute threshold: PRICE_CHANGE_REOPTIMIZE_ABS_EUR (0.01 €/kWh, new constant in const.py)
  • _last_price is always updated in the fallback branch, so the trigger can never get stuck

Tests

  • New tests: price moving 0 → 0.05 triggers re-optimization; 0 → 0.001 doesn't trigger but updates _last_price
  • Full suite green, pre-commit green

https://claude.ai/code/session_01ViddzhUiQT1rMibFjc2pn6


Generated by Claude Code

@github-actions github-actions Bot added enhancement New feature or improvement bug Something isn't working as expected labels Jun 11, 2026
@bvweerd bvweerd force-pushed the claude/fix-13-zero-price-fallback branch 2 times, most recently from 6eeb4d8 to e2357b6 Compare June 12, 2026 08:40
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
@bvweerd bvweerd force-pushed the claude/fix-13-zero-price-fallback branch from e2357b6 to 45fcaad Compare June 12, 2026 08:49
@bvweerd bvweerd merged commit 607709a into dev Jun 12, 2026
6 checks passed
@bvweerd bvweerd deleted the claude/fix-13-zero-price-fallback branch June 12, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant