Power: flag frozen outlet watts, draw the SmartPower Strip #42

Merged
jared merged 1 commits from stale-outlet-watts into main 2026-11-15 00:24:23 -05:00
Owner

Why

The outlet watts on the topology page were wrong, and the cause is upstream. UniFi's stat/device keeps serving one frozen set of USP PDU Pro outlet readings, while the unit's total (outlet_ac_power_consumption) stays live:

  • Every outlet reports 120.661 V, and the watts are identical to three decimals all session.
  • Those frozen outlets add up to about 321 W, against a live total of 593 W.
  • The UPS 2U Pro's outlets are live.
  • The integration v1 and v2 device APIs have no per-outlet power to use instead.

Gandalf now stops presenting frozen numbers as if they were live.

What changes

  • monitor.py: LinkStatsCollector._mark_stale_outlets fingerprints each power unit's metered outlet readings (watts and amps) on every poll. If they haven't changed for 15 minutes and at least one outlet draws power, it marks every metered outlet stale and sets outlets_stale_since on the device. Units whose outlets all read 0 and unmetered units (the USP Strip) are never flagged.
  • topology.py: passes stale through on each outlet and in power_in, and adds stale_since per source.
  • Topology page:
    • outlet rows say "stale" instead of watts
    • the ⚡ badge says "fed" instead of a number
    • feed lines say "(watts stale)"
    • a "to look at" chip reads "RPDU outlet watts frozen since HH:MM; its total is live"
  • Device page: the outlet table puts a "stale" badge on each reading and adds a note above it. The faceplate hover text says "(stale reading)".
  • USP Strip (UP6) faceplate:
    • traced from the render in Ubiquiti's datasheet and sized from its 229.5 x 111.5 mm footprint
    • three facing pairs of US outlets (1/2, 3/4, 5/6), four USB-C ports (UniFi outlet 7, "USB Outlets"), the U logo, the status LED and the cord
    • used on the topology card and on the strip's device page

Tests

  • Results: 479 passed; flake8 and bandit are clean; eslint is unchanged at the 21-warning baseline.
  • New TestStaleOutletReadings:
    • frozen readings past the limit are marked stale
    • moving readings stay live
    • idle zero readings are never stale
    • the unmetered strip is left alone
  • A new topology test checks that stale flags are passed through.

Screenshots (anonymised preview data, RPDU readings simulated as stale)

Summary chip RPDU outlet rows
SmartPower Strip

🤖 Generated with Claude Code

## Why The outlet watts on the topology page were wrong, and the cause is upstream. UniFi's `stat/device` keeps serving one frozen set of USP PDU Pro outlet readings, while the unit's total (`outlet_ac_power_consumption`) stays live: - Every outlet reports 120.661 V, and the watts are identical to three decimals all session. - Those frozen outlets add up to about 321 W, against a live total of 593 W. - The UPS 2U Pro's outlets are live. - The integration v1 and v2 device APIs have no per-outlet power to use instead. Gandalf now stops presenting frozen numbers as if they were live. ## What changes - **monitor.py:** `LinkStatsCollector._mark_stale_outlets` fingerprints each power unit's metered outlet readings (watts and amps) on every poll. If they haven't changed for 15 minutes and at least one outlet draws power, it marks every metered outlet `stale` and sets `outlets_stale_since` on the device. Units whose outlets all read 0 and unmetered units (the USP Strip) are never flagged. - **topology.py:** passes `stale` through on each outlet and in `power_in`, and adds `stale_since` per source. - **Topology page:** - outlet rows say "stale" instead of watts - the ⚡ badge says "fed" instead of a number - feed lines say "(watts stale)" - a "to look at" chip reads "RPDU outlet watts frozen since HH:MM; its total is live" - **Device page:** the outlet table puts a "stale" badge on each reading and adds a note above it. The faceplate hover text says "(stale reading)". - **USP Strip (UP6) faceplate:** - traced from the render in Ubiquiti's datasheet and sized from its 229.5 x 111.5 mm footprint - three facing pairs of US outlets (1/2, 3/4, 5/6), four USB-C ports (UniFi outlet 7, "USB Outlets"), the U logo, the status LED and the cord - used on the topology card and on the strip's device page ## Tests - Results: 479 passed; flake8 and bandit are clean; eslint is unchanged at the 21-warning baseline. - New `TestStaleOutletReadings`: - frozen readings past the limit are marked stale - moving readings stay live - idle zero readings are never stale - the unmetered strip is left alone - A new topology test checks that stale flags are passed through. ## Screenshots (anonymised preview data, RPDU readings simulated as stale) | | | |---|---| | Summary chip ![](https://code.lotusguild.org/LotusGuild/gandalf/raw/branch/pr-42-screenshots/01-summary.png) | RPDU outlet rows ![](https://code.lotusguild.org/LotusGuild/gandalf/raw/branch/pr-42-screenshots/02-rpdu-stale.png) | | SmartPower Strip ![](https://code.lotusguild.org/LotusGuild/gandalf/raw/branch/pr-42-screenshots/03-strip-card.png) | | 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-14 22:46:18 -05:00
Power: flag frozen outlet watts, draw the SmartPower Strip
Lint / JS (eslint) (push) Successful in 14s
Lint / Python (flake8) (push) Successful in 1m3s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m9s
Test / Python Tests (pytest) (push) Successful in 1m29s
Lint / Python (flake8) (pull_request) Successful in 1m9s
Lint / JS (eslint) (pull_request) Successful in 14s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m26s
Test / Python Tests (pytest) (pull_request) Successful in 1m48s
60d892badb
UniFi can keep serving one frozen set of USP PDU Pro outlet readings for hours
while the unit's total stays live (seen on prod: every outlet at 120.661 V with
the same watts all session, summing to 321 W of a live 593 W total). The monitor
now notices when a power unit's loaded outlet readings have not changed for 15
minutes and marks them stale. The topology page shows "stale" instead of watts,
the power badge says "fed", and a "to look at" chip says since when; the device
page marks the readings too.

Adds a UP6 (USP-Strip) faceplate traced from Ubiquiti's datasheet render: three
facing pairs of US outlets, four USB-C ports (outlet 7), the LED and the cord.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-15 00:24:21 -05:00
jared merged commit 3a1371e8b7 into main 2026-11-15 00:24:23 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#42