fix(sensor): read report timestamps in each unit's own timezone - #283
Open
andrew-blake wants to merge 10 commits into
Open
fix(sensor): read report timestamps in each unit's own timezone#283andrew-blake wants to merge 10 commits into
andrew-blake wants to merge 10 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## docs/pr-body-skill #283 +/- ##
===================================================
Coverage 93.21% 93.22%
===================================================
Files 44 44
Lines 2904 2922 +18
===================================================
+ Hits 2707 2724 +17
- Misses 197 198 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacks on
docs/pr-body-skill(#277) and needs nothing from it beyond a base: that branch is a docs-only change queued to merge first.The
/report/v1/endpoints keep each unit's datapoints in that unit's own local timezone, and/contextnames the zone per unit as an IANA string on the unit node. Requests now declare their window as UTC so the server converts it, and returned stamps are interpreted in the unit's zone before becoming alast_reading. Two faults compounded to hide each other: a window sent without an offset is taken as already-local, so it stops short of the present by the unit's offset, and a local stamp parsed as UTC yields an age that much too young. The combination presents a reading at least offset-hours old as current, which is the conditionlast_readingexists to expose (#200). Measurements, theto-shift test that identifies the behaviour on any unit, and the superseded evidence they replace are in ADR-022 anddocs/api/atw-api-reference.md.Key changes
parse_api_timestampaccepts a source timezone, defaulting to UTC so a caller without one is unaffected.AirToAirUnitandAirToWaterUnitcarrytime_zone, read from the unit node'stimeZonekey._report_paramsmarksfromandtoas UTC, which makes the server convert the window instead of reading it as local time.resolve_unit_timezoneresolves a unit's zone through Home Assistant's async resolver, falling back to UTC with a debug line for a missing or unrecognised name.timeZoneon every unit node and stamps report points in that unit's zone, so a mock-backed run exercises the conversion.What changes for users
last_readingon those sensors shows the instant the unit recorded the value. On a unit that has not produced a newer reading, the displayed value moves back by that unit's UTC offset, because the age it showed understated the truth by exactly that much. Nothing to do: the sensor value is unchanged and no history is rewritten.Risks accepted
fromearlier, which can widen the span by a calendar day, andinternaltemperaturesreturns 500 for windows spanning three. Every device reachable for testing sits at +1 or +2, so this is reasoned rather than measured. It would surface as water temperatures missing for users in the Americas, and the fix reverts to sending an offset-less window.to-shift probe. The fallback is to send unit-local wall-clock, which requires the unit's zone on the request path and so makes a unit with no reported zone worse off.parse_api_timestamp.AI Disclosure
Testing
make test: 395 api, 256 integration, 16 e2e.make test-integration-floor: 256 on thehacs.jsonHome Assistant floor.make type-checkandmake pre-commitclean.Europe/Stockholmunit, two requests one after the other differing only in whether the window declares UTC: the declared one reaches 89 minutes of data the other cannot, and both echo an identicalfrom, so the window gains no calendar days.zoneinfowarning in the Home Assistant log, which is the only tier that can check that, sincetests/apiruns without Home Assistant.last_readingmove back by exactly their offsets, 60 minutes for aEurope/Londonunit and 120 for aEurope/Stockholmone, on identical naive stamps. A restart re-polls, so a freshness improvement proves nothing here and the backward shift is the signal. No new integration error class, and the only blocking-call warnings name an unrelated third-party integration. Prod is running this from this branch on top of the unmerged stack below it.