Skip to content

Add unit tests for cumulative energy meter offset/rollover logic#17

Merged
Bre77 merged 1 commit into
mainfrom
fm/homey-t1-meter-tests
Jul 23, 2026
Merged

Add unit tests for cumulative energy meter offset/rollover logic#17
Bre77 merged 1 commit into
mainfrom
fm/homey-t1-meter-tests

Conversation

@Bre77

@Bre77 Bre77 commented Jul 23, 2026

Copy link
Copy Markdown
Member

Intent

  • Add direct unit coverage for updateCumulativeMeter in lib/TeslemetryDevice.ts, which has no tests today despite three past releases (0.1.2, 0.1.3, 0.2.0) fixing energy-meter/unit-conversion bugs in this area
    • Offset initialization from the existing capability value on the first reading
    • Monotonic accumulation across successive same-day readings
    • Day rollover, including back-to-back rollovers across several days
    • No-op behavior once destroyed is set, including mid-flight after the offset write but before the rest of the update completes
  • Test-only change: lib/TeslemetryDevice.ts is untouched

Note for reviewers

Writing these tests surfaced a gap, not fixed here: the day-rollover check only triggers on a dateKey change. A same-day raw reading that comes back lower than the previous one (e.g. a transient API glitch) is not guarded against and passes straight through as a decreasing capability value, which is exactly the kind of regression Homey's cumulative-meter energy tracking assumes can't happen. See the passes a lower same-day raw reading straight through as a decreasing value test, which documents the current behavior rather than asserting a fix. Flagging for a separate PR if that's worth guarding against.

Covers offset initialization, same-day accumulation, day rollover
across single and multiple boundaries, and the destroyed-device guard.
@Bre77
Bre77 merged commit b659005 into main Jul 23, 2026
2 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