This release fixes critical data corruption issues that affected both consumption and cost sensors in previous versions.
LatestFixed Issues
-
Race condition in historical fetch (sensor.py)
- async_add_external_statistics() is non-blocking, causing offset to be
read before previous month's data was written to DB - Fixed by reading offset ONCE at start and updating mathematically
- Each month now receives the previous month's final offset directly
- async_add_external_statistics() is non-blocking, causing offset to be
-
Cost sensor using wrong values (sensor.py)
- Cost was calculated using point['cumulative_kwh'] (without offset)
- This caused costs to reset to near-zero each month
- Fixed by using final_value (which includes offset) instead
-
Thread safety in migration (init.py)
- Migration tried to call clear_statistics() from main thread
- Recorder operations must run in recorder thread
- Fixed by deferring statistics clearing to background task
Migration (v3 → v4)
Existing users (v1.5.0 and earlier) will automatically:
- Clear ALL corrupted statistics (both consumption and cost)
- Re-fetch complete historical data with fixes applied
- Rebuild database with correct cumulative values
New users install directly with v4 (no migration needed).
Testing
Verified in production with:
- 14,015 data points spanning 20 months (584 days)
- 99.993% accuracy (1 missing point is DST anomaly: 2025-03-30 02:00 doesn't exist)
- All consumption values monotonically increasing
- All cost values correctly calculated with offset
Fixes #10
See: #10 (comment)