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

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>
This commit is contained in:
2026-11-14 22:46:04 -05:00
co-authored by Claude Opus 5.5
parent 206175df39
commit 60d892badb
8 changed files with 189 additions and 18 deletions
+27
View File
@@ -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 {
+6 -2
View File
@@ -292,10 +292,14 @@ function renderOutlets(d) {
<td><span class="dot-${o.on ? 'up' : 'down'}"></span></td>
<td>#${esc(o.index)}</td>
<td>${esc(o.name || '-')}</td>
<td class="device-num">${o.power_w === null || o.power_w === undefined ? '-' : `${o.power_w.toFixed(1)} W`}</td>
<td class="device-num">${o.power_w === null || o.power_w === undefined ? '-' : `${o.power_w.toFixed(1)} W${o.stale ? ' <span class="lt-badge" title="UniFi has been sending this same reading for a long time">stale</span>' : ''}`}</td>
<td>${o.auto_power_cycle ? '<span class="lt-badge">auto power-cycle</span>' : ''}</td>
</tr>`).join('');
return section('Outlets', `<div class="lt-table-wrap"><table class="lt-table">
const since = d.info.outlets_stale_since;
const note = since
? `<p class="g-page-sub">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.</p>`
: '';
return section('Outlets', `${note}<div class="lt-table-wrap"><table class="lt-table">
<caption class="lt-sr-only">PDU outlets</caption>
<thead><tr><th><span class="lt-sr-only">State</span></th><th>Outlet</th><th>Name</th><th>Power</th><th></th></tr></thead>
<tbody>${rows}</tbody></table></div>`);
+45 -1
View File
@@ -147,6 +147,18 @@ function outletFaceSvg(kind, w, h, idx) {
return `<rect class="fp-usbc" width="${w}" height="${h}" rx="${w / 2}"/>
<rect class="fp-usbc-tongue" x="${cx - 1}" y="4" width="2" height="${h - 8}" rx="1"/>`;
}
if (kind === 'usbc-h') {
return `<rect class="fp-usbc" width="${w}" height="${h}" rx="${h / 2}"/>
<rect class="fp-usbc-tongue" x="4" y="${cy - 1}" width="${w - 8}" height="2" rx="1"/>`;
}
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 `<rect class="fp-outlet-bare" width="${w}" height="${h}" rx="${w / 4}"/>
<rect class="fp-slot" x="${cx - 17}" y="${cy - 20}" width="5.5" height="17" rx=".8"/>
<rect class="fp-slot" x="${cx + 11.5}" y="${cy - 22}" width="5.5" height="19" rx=".8"/>
<path class="fp-slot" d="M${cx - 7} ${cy + 22} v-8 a7 7 0 0 1 14 0 v8 Z"/>`;
}
const face = `<rect class="fp-outlet-face" width="${w}" height="${h}" rx="3"/>`;
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 = {
</g>`;
},
},
// 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) =>
`<text class="fp-label fp-label-sm" x="836" y="${y + 5}" text-anchor="middle">${i + 1}</text>`).join('');
return `<path class="fp-cord" d="M0 223 H48"/>
<rect class="fp-cord-boot" x="26" y="203" width="26" height="40" rx="6"/>
<rect class="fp-body-white" x="48" y="2" width="918" height="442" rx="44"/>
<path class="fp-strip-logo" d="M120 206 v18 a10 10 0 0 0 20 0 v-18"/>
<rect class="fp-strip-led${online ? ' fp-strip-led-on' : ''}" x="198" y="196" width="8" height="54" rx="4"/>
<text class="fp-label fp-label-sm" x="896" y="420" text-anchor="middle">USB-C</text>
${usbNums}`;
},
},
};
function faceplateLegendSwatch(cls) {
+8
View File
@@ -1030,6 +1030,13 @@ tr.device-row.is-selected { background: var(--bg-tertiary); box-shadow: inset 3p
.fp-usbc-tongue { fill: #b9bcc2; }
.fp-outlet-is-off .fp-outlet-face { fill: #5b5c60; }
.fp-outlet-is-off .fp-usbc { fill: #66676b; }
.fp-outlet-bare { fill: #e6e6e8; stroke: #cfcfd2; stroke-width: 1; }
.fp-outlet-is-off .fp-outlet-bare { fill: #b9babe; }
.fp-cord { stroke: #d9d9db; stroke-width: 16; stroke-linecap: round; fill: none; }
.fp-cord-boot { fill: #cfcfd2; }
.fp-strip-logo { fill: none; stroke: #b9babe; stroke-width: 6; stroke-linecap: round; }
.fp-strip-led { fill: #c9cacd; }
.fp-strip-led-on { fill: #5ad7f0; filter: drop-shadow(0 0 4px #5ad7f0); }
.fp-outlet:hover .fp-hit { stroke: rgba(0,90,220,.55); }
.fp-outlet:focus-visible .fp-hit { stroke: #0058e0; fill: rgba(0,88,224,.14); }
.fp-outlet-state { fill: #8d8e93; }
@@ -1652,6 +1659,7 @@ body.fp-marks-off .fp-svg .fp-mark { display: none; }
.tp-outlet-watts { font-family: var(--font); font-size: 24px; fill: #e0a400; }
.tp-outlet-free .tp-outlet-target { fill: var(--text-muted); font-style: italic; }
.tp-outlet-off .tp-outlet-watts, .tp-outlet-off .tp-outlet-target { fill: #ff6b5e; }
.tp-outlet-stale .tp-outlet-watts { fill: var(--text-muted, #8a929c); font-style: italic; }
.tp-power-badge { font-family: var(--font); font-size: 26px; font-weight: 700; fill: #e0a400; }
.tp-power-off { fill: #ff6b5e; }
.tp-feeds { pointer-events: none; }
+32 -9
View File
@@ -103,6 +103,12 @@ function problemsOf(data) {
out.push({ kind: 'node', id: n.id, severity: n.status === 'down' || n.severity === 'critical' ? 'bad' : 'warn',
text: `${n.name}: ${bits.join(', ')}` });
});
(data.power || []).forEach(src => {
if (src.stale_since) {
out.push({ kind: 'node', id: src.node, severity: 'warn',
text: `${src.node} outlet watts frozen since ${sinceText(src.stale_since)}; its total is live` });
}
});
(data.power || []).forEach(src => src.outlets.forEach(o => {
if (o.on || !o.target) return;
const down = (byId[o.target] || {}).status === 'down';
@@ -132,6 +138,17 @@ function problemsOf(data) {
return out;
}
// "2026-11-14 22:48:00 UTC" as local time: just the time today, else the date and time
function sinceText(utc) {
const d = new Date(String(utc).replace(' UTC', 'Z').replace(' ', 'T'));
if (Number.isNaN(d.getTime())) return String(utc);
const time = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
return d.toDateString() === new Date().toDateString() ? time : `${d.toLocaleDateString()} ${time}`;
}
const STALE_TIP = 'UniFi has been sending the same outlet readings for a long time, so these watts are not live. '
+ 'The unit\'s total is still live.';
function speedClass(mbps) {
if (mbps >= 10000) return 'tp-s-10g';
if (mbps >= 1000) return 'tp-s-1g';
@@ -370,7 +387,7 @@ function artFor(node) {
case 'stub': return node.via && node.via.kind === 'patch_panel' ? patchPanelDrawing(node) : stubDrawing();
case 'group': return groupDrawing(node);
case 'ap': return apDrawing(node);
case 'strip': return stripDrawing(node);
case 'strip': return spec ? faceplateDrawing(node, node.model, 1100) : stripDrawing(node);
default:
if (spec && DESK_FACEPLATES[node.model]) return deskFaceplate(node);
if (spec) return faceplateDrawing(node, node.model, 1100, { rack: node.kind === 'ups', crop: !node.power });
@@ -476,14 +493,15 @@ function cardFor(node, linksByIface) {
const y = CARD_H + i * ROW_H;
rows[o.index] = y + ROW_H / 2;
const what = o.target || (o.match === 'cleared' ? 'nothing' : 'unassigned');
const cls = `tp-outlet-row${o.on ? '' : ' tp-outlet-off'}${o.target ? '' : ' tp-outlet-free'}`;
const tip = `${node.name} outlet ${o.index}${o.name ? ` "${o.name}"` : ''} · ${o.on ? 'on' : 'off'}${o.power_w != null ? ` · ${wattText(o.power_w)}` : ''} · feeds ${what}${o.match === 'saved' ? ' (set here)' : o.match === 'name' ? ' (from its name)' : o.match === 'mac' ? ' (from the MAC in its name)' : ''}${TOPO_CAN_EDIT ? ' · click to change' : ''}`;
const cls = `tp-outlet-row${o.on ? '' : ' tp-outlet-off'}${o.target ? '' : ' tp-outlet-free'}${o.stale ? ' tp-outlet-stale' : ''}`;
const tip = `${node.name} outlet ${o.index}${o.name ? ` "${o.name}"` : ''} · ${o.on ? 'on' : 'off'}${o.power_w != null ? ` · ${wattText(o.power_w)}${o.stale ? ' (stale)' : ''}` : ''} · feeds ${what}${o.match === 'saved' ? ' (set here)' : o.match === 'name' ? ' (from its name)' : o.match === 'mac' ? ' (from the MAC in its name)' : ''}${TOPO_CAN_EDIT ? ' · click to change' : ''}`;
const staleTip = o.stale ? ` · ${STALE_TIP}` : '';
return `<g class="${cls}" data-outlet-source="${esc(node.name)}" data-outlet="${o.index}"${TOPO_CAN_EDIT ? ' role="button" tabindex="0"' : ''}>
<title>${esc(tip)}</title>
<title>${esc(tip + staleTip)}</title>
<rect class="tp-outlet-hit" x="16" y="${y + 4}" width="${w - 32}" height="${ROW_H - 8}" rx="8"/>
<text class="tp-outlet-idx" x="34" y="${y + 31}">${o.index}</text>
<text class="tp-outlet-target" x="96" y="${y + 31}">${esc(what.length > 22 ? `${what.slice(0, 21)}…` : what)}</text>
<text class="tp-outlet-watts" x="${w - 34}" y="${y + 31}" text-anchor="end">${o.on ? esc(wattText(o.power_w)) : 'off'}</text>
<text class="tp-outlet-watts" x="${w - 34}" y="${y + 31}" text-anchor="end">${!o.on ? 'off' : o.stale ? 'stale' : esc(wattText(o.power_w))}</text>
</g>`;
}).join('');
h = CARD_H + list.length * ROW_H + (list.length ? 16 : 0);
@@ -492,9 +510,12 @@ function cardFor(node, linksByIface) {
let badge = '';
if ((node.power_in || []).length) {
const off = node.power_in.some(f => !f.on);
const stale = node.power_in.some(f => f.stale);
const watts = node.power_in.reduce((t, f) => t + (f.power_w || 0), 0);
const tip = node.power_in.map(f => `${f.source} outlet ${f.outlet}${f.on ? '' : ' (off)'}${f.power_w != null ? ` · ${wattText(f.power_w)}` : ''}`).join('; ');
badge = `<text class="tp-power-badge${off ? ' tp-power-off' : ''}" x="${w - 34}" y="108" text-anchor="end"><title>${esc(`Fed by ${tip}`)}</title>⚡ ${off ? 'off' : esc(wattText(watts) || 'fed')}</text>`;
const tip = node.power_in.map(f => `${f.source} outlet ${f.outlet}${f.on ? '' : ' (off)'}${f.power_w != null ? ` · ${wattText(f.power_w)}${f.stale ? ' (stale)' : ''}` : ''}`).join('; ');
// A frozen reading is not shown as if it were live
const text = off ? 'off' : stale ? 'fed' : (wattText(watts) || 'fed');
badge = `<text class="tp-power-badge${off ? ' tp-power-off' : ''}" x="${w - 34}" y="108" text-anchor="end"><title>${esc(`Fed by ${tip}${stale ? `. ${STALE_TIP}` : ''}`)}</title>⚡ ${esc(text)}</text>`;
}
const maxChars = Math.floor((w - 130) / 27);
const name = node.name.length > maxChars ? `${node.name.slice(0, maxChars - 1)}…` : node.name;
@@ -1045,10 +1066,12 @@ function drawFeeds(id) {
const c = Math.max(160, Math.abs(from.x - B.x) * 0.4);
const d = `M${from.x} ${from.y} C${from.x - c} ${from.y} ${B.x + c} ${B.y} ${B.x} ${B.y}`;
const mx = (from.x + B.x) / 2, my = (from.y + B.y) / 2;
const text = `⚡ ${target} ${!o.on ? 'off' : o.stale ? '(watts stale)' : wattText(o.power_w)}`;
const tw = Math.max(300, text.length * 15 + 40);
return `<g class="tp-feed${o.on ? '' : ' tp-feed-off'}"><path d="${d}"/>
<circle cx="${B.x}" cy="${B.y}" r="10"/>
<g class="tp-tag tp-feed-tag" transform="translate(${mx} ${my})"><rect x="-150" y="-26" width="300" height="44" rx="22"/>
<text y="6" text-anchor="middle">⚡ ${esc(target)} ${o.on ? esc(wattText(o.power_w)) : 'off'}</text></g></g>`;
<g class="tp-tag tp-feed-tag" transform="translate(${mx} ${my})"><rect x="${-tw / 2}" y="-26" width="${tw}" height="44" rx="22"/>
<text y="6" text-anchor="middle">${esc(text)}</text></g></g>`;
}).join('');
// Everything at either end of a feed stays lit while the path is traced
return new Set(pairs.flatMap(p => [p.target, ...((state.data.power || []).filter(src => src.outlets.includes(p.o)).map(src => src.node))]));
+46
View File
@@ -485,6 +485,52 @@ class TestWanIncident:
assert not mon.tickets.create.called and not mon.tickets.comment.called
class TestStaleOutletReadings:
@staticmethod
def _pdu(w1=20.622, w2=0.0):
return {'RPDU': {'outlets': [
{'index': 1, 'power_w': w1, 'current_a': 0.322},
{'index': 2, 'power_w': w2, 'current_a': 0.0},
{'index': 3, 'power_w': None, 'current_a': None}, # USB: never metered
]}}
def _collector(self):
c = monitor.LinkStatsCollector.__new__(monitor.LinkStatsCollector)
c._outlet_readings = {}
return c
def test_readings_frozen_past_the_limit_are_stale(self):
c = self._collector()
c._mark_stale_outlets(self._pdu(), 1000.0)
later = self._pdu()
c._mark_stale_outlets(later, 1000.0 + c.OUTLET_STALE_AFTER_S)
assert later['RPDU']['outlets_stale_since'] == '1970-01-01 00:16:40 UTC'
assert [o.get('stale') for o in later['RPDU']['outlets']] == [True, True, None]
def test_moving_readings_are_live(self):
c = self._collector()
c._mark_stale_outlets(self._pdu(), 1000.0)
c._mark_stale_outlets(self._pdu(w1=21.0), 1000.0 + c.OUTLET_STALE_AFTER_S - 1)
later = self._pdu(w1=21.0)
c._mark_stale_outlets(later, 1000.0 + c.OUTLET_STALE_AFTER_S + 60)
assert 'outlets_stale_since' not in later['RPDU']
assert not any(o.get('stale') for o in later['RPDU']['outlets'])
def test_idle_outlets_reading_zero_are_not_stale(self):
c = self._collector()
c._mark_stale_outlets(self._pdu(w1=0.0), 1000.0)
later = self._pdu(w1=0.0)
c._mark_stale_outlets(later, 1000.0 + 10 * c.OUTLET_STALE_AFTER_S)
assert 'outlets_stale_since' not in later['RPDU']
def test_unmetered_strip_is_left_alone(self):
c = self._collector()
strip = {'USP Strip': {'outlets': [{'index': 1, 'power_w': None}]}}
c._mark_stale_outlets(strip, 1000.0)
c._mark_stale_outlets(strip, 1000.0 + 10 * c.OUTLET_STALE_AFTER_S)
assert 'outlets_stale_since' not in strip['USP Strip'] and 'USP Strip' not in c._outlet_readings
class TestUnifiDeviceDetail:
def test_parses_string_stats_and_outlets(self):
d = monitor.UnifiClient._device_detail({
+15 -1
View File
@@ -403,9 +403,23 @@ class TestPower:
def test_devices_know_what_feeds_them(self):
g = self._graph()
assert node(g, 'host-c')['power_in'] == [{'source': 'RPDU', 'outlet': 16, 'on': True, 'power_w': 131.7}]
assert node(g, 'host-c')['power_in'] == [{'source': 'RPDU', 'outlet': 16, 'on': True, 'power_w': 131.7,
'stale': False}]
assert node(g, 'host-b')['power_in'] == []
def test_frozen_readings_are_passed_on_as_stale(self):
snapshot, link_stats, modem = network()
link_stats['unifi_devices']['RPDU']['outlets'] = [
dict(o, stale=True) if o.get('power_w') is not None else o for o in self.OUTLETS]
link_stats['unifi_devices']['RPDU']['outlets_stale_since'] = '2026-11-14 22:48:00 UTC'
link_stats['host_macs'] = {'02:00:5e:00:0a:01': ['host-c', 'nic0']}
g = topology.build_graph(snapshot, link_stats, modem, [], [], [], None, [])
src = next(s for s in g['power'] if s['node'] == 'RPDU')
assert src['stale_since'] == '2026-11-14 22:48:00 UTC'
assert src['outlets'][[o['index'] for o in src['outlets']].index(16)]['stale'] is True
assert node(g, 'host-c')['power_in'][0]['stale'] is True
assert next(s for s in g['power'] if s['node'] == 'UPS 2U Pro')['stale_since'] is None
def test_a_power_device_does_not_feed_itself(self):
out = self._outlets(self._graph(outlets=[{'index': 1, 'name': 'RPDU spare', 'on': True}]))
assert out[1]['target'] is None
+10 -5
View File
@@ -144,8 +144,9 @@ def build_power(nodes: Dict[str, dict], link_stats: dict, feeds: List[dict]) ->
In order: an assignment saved on the topology page (target '' means nothing), then the
outlet's name if it names a device ("storage-01", "Dream Machine Pro", or "AT&T Modem" for
the modem), then a MAC in its name that belongs to a host NIC or a UniFi device.
Returns [{node, power_w, outlets: [{index, name, on, power_w, auto_power_cycle, target,
match: saved|cleared|name|mac|none}]}].
Returns [{node, power_w, stale_since, outlets: [{index, name, on, power_w, stale,
auto_power_cycle, target, match: saved|cleared|name|mac|none}]}]. stale_since is set when
the monitor saw the unit's outlet readings stop changing (UniFi serving a frozen snapshot).
"""
known = {_norm(n['name']): n['name'] for n in nodes.values() if n['kind'] not in ('stub', 'internet')}
modem = next((n['name'] for n in nodes.values() if n['kind'] == 'modem'), None)
@@ -181,9 +182,11 @@ def build_power(nodes: Dict[str, dict], link_stats: dict, feeds: List[dict]) ->
target = macs.get(m.group(1).lower().replace('-', ':')) if m else None
how = 'mac' if target else 'none'
rows.append({'index': idx, 'name': text, 'on': o.get('on') is not False,
'power_w': o.get('power_w'), 'auto_power_cycle': bool(o.get('auto_power_cycle')),
'power_w': o.get('power_w'), 'stale': bool(o.get('stale')),
'auto_power_cycle': bool(o.get('auto_power_cycle')),
'target': target, 'match': how})
sources.append({'node': node['name'], 'power_w': node.get('power_w'), 'outlets': rows})
sources.append({'node': node['name'], 'power_w': node.get('power_w'), 'outlets': rows,
'stale_since': node.get('outlets_stale_since')})
return sources
@@ -289,6 +292,7 @@ def build_graph(snapshot: dict, link_stats: dict, modem: Optional[dict], events:
info = unifi_info.get(name) or {}
node['power_w'] = info.get('power_w')
node['outlets'] = info.get('outlets') or []
node['outlets_stale_since'] = info.get('outlets_stale_since')
node_alerts = alerts.get(name, [])
node['alerts'] = node_alerts[:10]
node['alert_count'] = len(node_alerts)
@@ -487,7 +491,8 @@ def build_graph(snapshot: dict, link_stats: dict, modem: Optional[dict], events:
for o in src['outlets']:
if o['target'] in nodes:
nodes[o['target']]['power_in'].append(
{'source': src['node'], 'outlet': o['index'], 'on': o['on'], 'power_w': o['power_w']})
{'source': src['node'], 'outlet': o['index'], 'on': o['on'], 'power_w': o['power_w'],
'stale': o['stale']})
if not switches:
warnings.append('No UniFi switch data yet: the monitor has not reported any ports')