From 60d892badb745a24f80f9f21697360c6c5f3b89f Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 14 Nov 2026 22:46:04 -0500 Subject: [PATCH] Power: flag frozen outlet watts, draw the SmartPower Strip 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 --- monitor.py | 27 +++++++++++++++++++++++++ static/device.js | 8 ++++++-- static/faceplates.js | 46 +++++++++++++++++++++++++++++++++++++++++- static/style.css | 8 ++++++++ static/topology.js | 41 ++++++++++++++++++++++++++++--------- tests/test_monitor.py | 46 ++++++++++++++++++++++++++++++++++++++++++ tests/test_topology.py | 16 ++++++++++++++- topology.py | 15 +++++++++----- 8 files changed, 189 insertions(+), 18 deletions(-) diff --git a/monitor.py b/monitor.py index c525a5e..3d50550 100644 --- a/monitor.py +++ b/monitor.py @@ -659,6 +659,32 @@ class LinkStatsCollector: # State for UniFi rate calculation (previous snapshot + timestamp) self._prev_unifi: Dict[str, dict] = {} self._prev_unifi_time: float = 0.0 + # Per power unit: (its outlets' last readings, when they last changed) + self._outlet_readings: Dict[str, tuple] = {} + + # Live readings from a loaded outlet change every poll (watts and amps to three decimals). + # When none of them has moved for this long, UniFi is serving a frozen snapshot: the USP PDU + # Pro can keep reporting one set of outlet readings for hours while its total stays live. + OUTLET_STALE_AFTER_S = 15 * 60 + + def _mark_stale_outlets(self, devices: Dict[str, dict], now: float) -> None: + """Mark each metered outlet 'stale' and set the device's 'outlets_stale_since' (UTC) + when a power unit's outlet readings have not changed for OUTLET_STALE_AFTER_S.""" + for name, info in devices.items(): + metered = [o for o in info.get('outlets') or [] if o.get('power_w') is not None] + if not metered: + continue + readings = tuple((o.get('index'), o.get('power_w'), o.get('current_a')) for o in metered) + prev = self._outlet_readings.get(name) + since = prev[1] if prev and prev[0] == readings else now + self._outlet_readings[name] = (readings, since) + # All-zero outlets legitimately read the same every time + loaded = any(o.get('power_w') for o in metered) + if loaded and now - since >= self.OUTLET_STALE_AFTER_S: + stamp = datetime.fromtimestamp(since, timezone.utc) + info['outlets_stale_since'] = stamp.strftime('%Y-%m-%d %H:%M:%S UTC') + for o in metered: + o['stale'] = True # ------------------------------------------------------------------ # SSH collection (via Pulse worker) @@ -929,6 +955,7 @@ class LinkStatsCollector: logger.warning(f'UniFi switch port collection failed: {e}') unifi_devices = (self.unifi.get_device_details() or {}) if self.unifi else {} + self._mark_stale_outlets(unifi_devices, time.time()) host_macs = self._resolve_neighbors(unifi_switches, unifi_devices, instance_map) return { diff --git a/static/device.js b/static/device.js index c9afcb1..865d97a 100644 --- a/static/device.js +++ b/static/device.js @@ -292,10 +292,14 @@ function renderOutlets(d) { #${esc(o.index)} ${esc(o.name || '-')} - ${o.power_w === null || o.power_w === undefined ? '-' : `${o.power_w.toFixed(1)} W`} + ${o.power_w === null || o.power_w === undefined ? '-' : `${o.power_w.toFixed(1)} W${o.stale ? ' stale' : ''}`} ${o.auto_power_cycle ? 'auto power-cycle' : ''} `).join(''); - return section('Outlets', `
+ const since = d.info.outlets_stale_since; + const note = since + ? `

The outlet readings have not changed since ${esc(since)}: UniFi is sending a frozen snapshot, so they are not live. The power draw total is live.

` + : ''; + return section('Outlets', `${note}
${rows}
PDU outlets
StateOutletNamePower
`); diff --git a/static/faceplates.js b/static/faceplates.js index 682231b..debb02a 100644 --- a/static/faceplates.js +++ b/static/faceplates.js @@ -147,6 +147,18 @@ function outletFaceSvg(kind, w, h, idx) { return ` `; } + if (kind === 'usbc-h') { + return ` + `; + } + if (kind === 'us-bare') { + // A US socket moulded straight into a white body (the SmartPower Strip): no face plate, + // just a shallow recess with the two blades over the round ground + return ` + + + `; + } const face = ``; if (kind === 'horizontal') { return `${face} @@ -168,7 +180,7 @@ function outletTitle(o, data) { if (data) { if (data.name && data.name !== parts[0]) parts.push(data.name); parts.push(data.on === false ? 'off' : 'on'); - if (data.power_w != null) parts.push(`${data.power_w.toFixed(1)} W`); + if (data.power_w != null) parts.push(`${data.power_w.toFixed(1)} W${data.stale ? ' (stale reading)' : ''}`); if (data.auto_power_cycle) parts.push('auto power-cycle'); } return lt.escHtml(parts.join(' · ')); @@ -566,6 +578,38 @@ const FACEPLATES = { `; }, }, + + // UniFi SmartPower Strip (USP-Strip), top face. Traced from the product render on Ubiquiti's + // datasheet (images.salsify.com/.../046c9c047ca057faf25eb38f48c598318c9ae699.pdf, page 1) and + // sized from its 229.5 x 111.5 mm footprint at 4 units per mm, plus the cord on the left. + // Six AC outlets in three facing pairs (1 over 2, 3 over 4, 5 over 6), and four USB-C ports + // that UniFi switches together as outlet 7, "USB Outlets". + UP6: { + width: 968, height: 446, frameClass: 'fp-desk', noBody: true, + label: 'SmartPower Strip', + legend: [['outlet-on', 'outlet on'], ['outlet-off', 'outlet off']], + ports: [], + outlets: [ + ...[338, 502, 664].flatMap((cx, i) => [ + { idx: 2 * i + 1, kind: 'us-bare', flip: true, x: cx - 33, y: 86, w: 66, h: 66, label: [cx - 16, 232] }, + { idx: 2 * i + 2, kind: 'us-bare', x: cx - 33, y: 294, w: 66, h: 66, label: [cx + 22, 232] }, + ]), + ...[84, 165, 250, 335].map((y, i) => ({ + idx: 7, kind: 'usbc-h', x: 852, y: y - 7, w: 40, h: 14, label: i === 3 ? [872, y + 46] : null, + })), + ], + decor({ online }) { + const usbNums = [84, 165, 250, 335].map((y, i) => + `${i + 1}`).join(''); + return ` + + +