Skip to content

Keep live stats and today’s self-powered % honest when a meter is down - #981

Merged
frahlg merged 1 commit into
masterfrom
cursor/stale-meter-live-stats-5640
Aug 27, 2026
Merged

Keep live stats and today’s self-powered % honest when a meter is down#981
frahlg merged 1 commit into
masterfrom
cursor/stale-meter-live-stats-5640

Conversation

@frahlg

@frahlg frahlg commented Aug 26, 2026

Copy link
Copy Markdown
Member

Accepted text proposal

Follow-up to merged #980 (Bugbot + Codex review on that PR). Same accepted scope: a quiet meter must not be drawn as live zeros.

What changed

  • Live stats strip above the chart now matches the Values tiles: configured-but-offline solar/battery/SoC render , not 0 W / 0.0 %.
  • % SELF-POWERED TODAY is computed from energy.today kWh only. Instantaneous load_w still blanks % SELF-POWERED NOW.
  • First /api/status is cached raw and replayed when energy-flow-readings.js assigns the mapper, not only when <ftw-energy-flow> upgrades.

Why

#980 stopped the hero and Values tiles from drawing a stale meter as 0 W balanced. Two leftover surfaces still lied:

  1. Site-level pv_w / bat_w / bat_soc become 0 once offline drivers are excluded from the live balance. The stats strip fed those zeros.
  2. Today’s self-powered share is historical kWh. Gating it on live load_w hid a day that already happened for the whole outage.

Codex also noted the mapper lives in the deferred module graph, so a fast first status could be dropped until the next 2 s poll. Replay now waits for the mapper as well as the custom element.

Not changing: GRID planet Math.abs + “exporting” subtitle. fmtKw would print a minus next to that word, which is the raw sign the hero never shows. Values tiles already keep the signed watt.

Boundaries and safety

  • No control, dispatch, or protocol change.
  • Live % still requires a known instantaneous load.
  • Houses with no battery configured still show SoC as they did before.

Open PRs: #968 touches web/app.js only at renderModeCatalog (planner buttons). This PR edits the live-stats / hero paint path only.

Verification

  • node --test web/energy-flow-readings.test.mjs web/dashboard-simplification.test.mjs web/javascript-syntax.test.mjs
  • Offline hybrid inverter mock (grid_w/load_w null, pv_w/bat_w/bat_soc 0, driver last-known still present):
    • Flow: GRID/SOLAR/BATTERY / no data, EV 0 W idle, hub 63% SELF-POWERED TODAY, no live NOW %
    • Live stats: GRID/PV/LOAD/BATTERY/SoC all
    • Values: SOLAR/GRID/HOME/BATTERY / no data, EV 0 W charger

Flow hub keeps 63% self-powered today while live watts are unknown
Live stats strip shows dashes not 0 W
Values tiles say no data

Checklist

  • The diff implements one accepted scope and does not add follow-on work.
  • I checked open pull requests that touch the same files.
  • Tests cover the changed behaviour and its failure path.
  • A human reviewed every changed web/UI view in a browser, or no UI changed.
  • A Changeset is included, or the change is exempt.
  • Every commit has a DCO sign-off.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Site-level pv_w/bat_w become 0 when those drivers are offline, so the
live stats strip still drew 0 W after the Values tiles said no data.
Today's self-powered share is kWh already in the box; it no longer
disappears just because the live meter is quiet. Replay the first
status payload when the flow mapper lands, not only when the custom
element upgrades.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg marked this pull request as ready for review August 26, 2026 13:13

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: Cursor Bugbot completed successfully with no findings that need human review, and no approval policy requires a human. No reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes two related honesty bugs when a meter/inverter goes offline:

  • The live-stats strip (Grid/PV/Battery/SoC tiles) no longer paints a fake 0 W for a configured-but-offline PV or battery — falls back to null/"—" like the Values tiles already do.
  • Today's self-powered % no longer blanks out just because the instantaneous meter reading is null. It's derived from already-accumulated kWh, so a quiet meter shouldn't erase a day that already happened.

Also factors the flow-diagram paint into paintEnergyFlow() and caches the raw status (lastFlowStatus) so it can repaint once either the readings mapper module or the <ftw-energy-flow> element finishes upgrading — avoids sitting in the loading skeleton for an extra poll cycle.

Test coverage added for both changes (dashboard-simplification.test.mjs, energy-flow-readings.test.mjs) and existing tests updated to match the refactor. No correctness or security issues from my read.

Safe to merge from my read.

@frahlg
frahlg merged commit db39491 into master Aug 27, 2026
17 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.

3 participants