Skip to content

Add guarded historical statistics transfer for measurement sensors - #2

Merged
FortranFour merged 4 commits into
mainfrom
feature/statistics-transfer
Oct 25, 2026
Merged

FortranFour merged 4 commits into
mainfrom
feature/statistics-transfer

Conversation

@FortranFour

@FortranFour FortranFour commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Device Replacer currently replaces configuration references while leaving the old sensor's statistics behind. This adds a separate, reviewed operation that renames an eligible recorder series to a fresh replacement sensor ID, preserving its hourly and retained five-minute measurements under the original numeric metadata ID.

Related to #1. This is a deliberately limited first implementation; it does not close the broader request for merging existing series or transferring cumulative energy counters.

Behavior and limits

  • Available in single-entity mode and for confirmed device entity mappings, independently of configuration reference edits.
  • Both sensors must remain registered, disabled and unloaded, declare measurement state class, and have matching known device classes and nonempty units.
  • Only recorder-owned arithmetic measurement series with retained rows are eligible. Existing destination metadata (even without rows), cumulative counters, unit conversions, circular means, external statistics and removed/unverifiable sources are blocked.
  • Uses Home Assistant's queued Python recorder metadata API; no direct SQL, schema changes, measurement-row copies, raw-history changes or Energy settings changes.
  • Session-owned, expiring previews are revalidated immediately before execution. Recorder completion is followed by metadata/ID verification because a refused rename can be silent.
  • A durable audit is written before recorder work. Timeout/cancellation/unverified results consume the token and block further transfers involving those IDs across restarts. Check outcome can reconcile a provably completed late rename without retrying it.
  • Statistics audits are excluded from configuration Restore, including a backend rejection. Recovery requires a database-inclusive backup.

Validation

  • 99 standalone Python tests passed, including preflight rejection, changed metadata/identities, session/expiry/consent checks, timeout/cancellation/silent refusal, persistence across restart and audit reconciliation.
  • Four real Home Assistant 2026.3.0 tests passed against a temporary SQLite database: hourly/five-minute row and metadata-ID preservation with unchanged raw history; destination collision refusal; a subsequent sensor statistics compilation under the same ID; timeout followed by verified late completion.
  • Frontend unit tests passed. Headless Chromium workflows and horizontal overflow checks passed in both device and entity modes at 1360px and 390px, including statistics confirmation and exclusion from configuration Restore.
  • JavaScript syntax, repository/package validation and git whitespace checks passed. A pinned HA recorder job is added to CI.

Version 1.2.0 is prepared as a testing prerelease. The .github/prerelease.json request triggers a prerelease-only publishing workflow on merge to main: it reruns checks, creates the version tag at the checked merge commit, uploads the installation ZIP and checksums, and explicitly uses --prerelease --latest=false. The latest stable release remains v1.1.3. No production HA installation has been modified; other database engines and HA versions still require validation.

@FortranFour
FortranFour marked this pull request as ready for review October 25, 2026 00:04
@FortranFour
FortranFour merged commit e571bd9 into main Oct 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant