mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
Introduced TibberPricesMidnightHandler to prevent duplicate midnight turnover when multiple timers fire simultaneously. Problem: Timer #1 (API poll) and Timer #2 (quarter-hour refresh) both wake at midnight, each detecting day change and triggering cache clear. Race condition caused duplicate turnover operations. Solution: - Atomic flag coordination: First timer sets flag, subsequent timers skip - Persistent state survives HA restart (cache stores last_turnover_time) - Day-boundary detection: Compares current.date() vs last_check.date() - 13 comprehensive tests covering race conditions and HA restart scenarios Architecture: - coordinator/midnight_handler.py: 165 lines, atomic coordination logic - coordinator/core.py: Integrated handler in coordinator initialization - coordinator/listeners.py: Delegate midnight check to handler Impact: Eliminates duplicate cache clears at midnight. Single atomic turnover operation regardless of how many timers fire simultaneously. |
||
|---|---|---|
| .. | ||
| api | ||
| binary_sensor | ||
| config_flow_handlers | ||
| coordinator | ||
| custom_translations | ||
| entity_utils | ||
| sensor | ||
| services | ||
| translations | ||
| utils | ||
| __init__.py | ||
| config_flow.py | ||
| const.py | ||
| data.py | ||
| diagnostics.py | ||
| entity.py | ||
| manifest.json | ||
| services.yaml | ||