Skip to content

Home load history: timezone-aware datetimes and additive backfill on manual collection #42

Description

@markoceri

Problem

Two issues affect the home load consumption history.

  1. Timezone mismatch. While building the per-device consumption in the optimization loop, the 24h look-back window is created with a naive datetime.now(), but Home Assistant and the persistence layer return timezone-aware (UTC) timestamps. The comparison fails with:

    Error getting load history for device '...': can't compare offset-naive and offset-aware datetimes
    

    The same naive/aware mix affects the history purge cut-off.

  2. Manual collection ignores the look-back window. When power points already exist for a device, a manual collection only fetches incrementally from the last stored point, ignoring the requested lookback_hours. Requesting e.g. 30 days returns only the few most recent points and never backfills internal gaps.

Expected

  • History datetimes are consistently timezone-aware (UTC).
  • A manual collection honours the requested look-back window and backfills missing data additively, without dropping already-stored points (bounded by Home Assistant's recorder retention).

Notes

The scheduled periodic collection stays incremental for efficiency.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions