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 ` + + +