Commit 2ac9d2d
fix(web): stop the /entity page reporting a status it never held (#4304)
The /entity page showed two GivEnergy Cloud inverters' status sensors
disagreeing with themselves: the timeline chart drew one continuous
"Normal" bar while the history table reported "Lost" for the same hours,
and a table row could report "Lost" while every 5-minute slot listed
under it read "Normal". Both views were wrong, in different ways.
History table (build_entity_history_table_data):
- A row reported the last sample taken inside its window rather than the
state across it, so one momentary "Lost" record at 21:57 made the whole
21:30 row read "Lost". Carry-forward then repeated that value into every
later slot with no sample of its own, turning a blip into hours of
apparent downtime. Every 30-minute row and 5-minute slot now reports the
state as of its own timestamp - the most recent record at or before it -
via a new state_as_of_slots() helper.
Note this is the rule 7248a75 (#4291) established when it fixed buckets
keeping the oldest sample instead of the newest; the bucket-summary idea
itself was the problem.
- Detail rows were the offsets -5..-25, i.e. the half hour BEFORE the row,
so expanding a row described a different window and contradicted the row
it sat under. They are now the 5-minute marks inside the row's own window.
Timeline chart (render_timeline_chart):
- State records were downsampled by array index (every Nth, max 288) before
being folded into ranges. For a categorical series that does not lower the
resolution, it rewrites history: whenever the step kept landing on one
phase of a flapping signal, every occurrence of the other state was erased
and the survivors merged into one long run. 8640 records alternating
Normal/Lost every minute rendered as a single 8639-minute "Normal" bar.
Ranges are now built from every record; only transitions emit a range, so
an entity that rarely changes stays cheap.
- Records were sorted by raw timestamp string. HA/DB history is UTC while
get_history_with_now() appends the current state stamped in local time, so
a string sort ordered records by their offset text and could truncate the
timeline early. Timestamps are parsed once and sorted by instant.
- A rangeBar point's "x" is the y-axis category, and every GivEnergy Cloud
inverter publishes a status sensor named "Status", so both inverters
collapsed onto a single unlabelled row. Colliding names are now
disambiguated with the entity_id.
Two consequences of the table change: a blip falling between two 5-minute
marks is no longer visible there (the chart shows every transition), and the
oldest row can read "-" where nothing had been recorded by that timestamp
instead of borrowing a reading taken later in the window.
Extends tests/test_web_history_table.py and tests/test_web_charts.py; the new
assertions were each confirmed to fail against the unfixed code.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 7b5fcdb commit 2ac9d2d
3 files changed
Lines changed: 262 additions & 193 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
19 | 99 | | |
20 | 100 | | |
21 | 101 | | |
| |||
69 | 149 | | |
70 | 150 | | |
71 | 151 | | |
| 152 | + | |
| 153 | + | |
72 | 154 | | |
0 commit comments