node-red-contrib-unifi-ultimate 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -8
- package/nodes/unifi-access-config.html +4 -3
- package/nodes/unifi-access-device.html +44 -6
- package/nodes/unifi-access-device.js +94 -6
- package/nodes/unifi-network-config.html +15 -5
- package/nodes/unifi-network-config.js +288 -0
- package/nodes/unifi-network-control-poe.html +2 -7
- package/nodes/unifi-network-control-poe.js +2 -1
- package/nodes/unifi-network-device.html +79 -7
- package/nodes/unifi-network-device.js +439 -19
- package/nodes/unifi-network-presence.html +2 -7
- package/nodes/unifi-network-presence.js +2 -1
- package/nodes/unifi-protect-config.html +4 -3
- package/nodes/unifi-protect-device.html +44 -6
- package/nodes/unifi-protect-device.js +82 -9
- package/nodes/utils/unifi-access-device-registry.js +142 -5
- package/nodes/utils/unifi-network-device-registry.js +95 -0
- package/nodes/utils/unifi-protect-device-registry.js +107 -3
- package/nodes/utils/unifi-protect-field-metadata.js +21 -1
- package/package.json +2 -2
|
@@ -1422,6 +1422,294 @@ module.exports = function(RED) {
|
|
|
1422
1422
|
};
|
|
1423
1423
|
}
|
|
1424
1424
|
|
|
1425
|
+
function parseTemperatureNumber(value) {
|
|
1426
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1427
|
+
return value;
|
|
1428
|
+
}
|
|
1429
|
+
if (typeof value === "string") {
|
|
1430
|
+
const normalized = value.trim().replace(",", ".");
|
|
1431
|
+
if (!normalized) {
|
|
1432
|
+
return undefined;
|
|
1433
|
+
}
|
|
1434
|
+
const parsed = Number.parseFloat(normalized);
|
|
1435
|
+
if (Number.isFinite(parsed)) {
|
|
1436
|
+
return parsed;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
return undefined;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
function normalizeTemperatureCelsius(value, unit) {
|
|
1443
|
+
const parsed = parseTemperatureNumber(value);
|
|
1444
|
+
if (!Number.isFinite(parsed)) {
|
|
1445
|
+
return undefined;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
const normalizedUnit = normalizeString(unit).toLowerCase();
|
|
1449
|
+
let celsius = parsed;
|
|
1450
|
+
if (["f", "fahrenheit"].includes(normalizedUnit)) {
|
|
1451
|
+
celsius = (parsed - 32) * 5 / 9;
|
|
1452
|
+
} else if (["k", "kelvin"].includes(normalizedUnit)) {
|
|
1453
|
+
celsius = parsed - 273.15;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
return Math.round(celsius * 10) / 10;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
function normalizeTemperatureLabel(key, fallbackLabel) {
|
|
1460
|
+
const explicit = normalizeString(fallbackLabel);
|
|
1461
|
+
const raw = explicit || normalizeString(key) || "temperature";
|
|
1462
|
+
const compact = raw
|
|
1463
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
1464
|
+
.replace(/[_-]+/g, " ")
|
|
1465
|
+
.replace(/\b(temp|temperature|celsius|fahrenheit|kelvin)\b/ig, " ")
|
|
1466
|
+
.replace(/\s{2,}/g, " ")
|
|
1467
|
+
.trim();
|
|
1468
|
+
|
|
1469
|
+
if (!compact) {
|
|
1470
|
+
return "Temperature";
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
return compact
|
|
1474
|
+
.split(" ")
|
|
1475
|
+
.map((part) => {
|
|
1476
|
+
const upper = part.toUpperCase();
|
|
1477
|
+
if (["CPU", "PHY", "SFP", "PSU", "PCB"].includes(upper)) {
|
|
1478
|
+
return upper;
|
|
1479
|
+
}
|
|
1480
|
+
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
1481
|
+
})
|
|
1482
|
+
.join(" ");
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function isTemperatureKey(key) {
|
|
1486
|
+
const normalized = normalizeString(key);
|
|
1487
|
+
return /(^|[_\-.])temp(erature)?($|[_\-.])/i.test(normalized)
|
|
1488
|
+
|| /Temperature$/.test(normalized)
|
|
1489
|
+
|| /^temp(erature)?$/i.test(normalized);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
function collectTemperatureReadings(source, sourceName) {
|
|
1493
|
+
const readings = [];
|
|
1494
|
+
const seen = new Set();
|
|
1495
|
+
|
|
1496
|
+
function addReading(name, rawValue, unit, key, path) {
|
|
1497
|
+
const valueC = normalizeTemperatureCelsius(rawValue, unit);
|
|
1498
|
+
if (!Number.isFinite(valueC)) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
const label = normalizeTemperatureLabel(key, name);
|
|
1503
|
+
const normalizedPath = normalizeString(path || key || label);
|
|
1504
|
+
const dedupeKey = `${sourceName}:${label.toLowerCase()}:${valueC}:${normalizedPath.toLowerCase()}`;
|
|
1505
|
+
if (seen.has(dedupeKey)) {
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
seen.add(dedupeKey);
|
|
1509
|
+
readings.push({
|
|
1510
|
+
name: label,
|
|
1511
|
+
valueC,
|
|
1512
|
+
unit: "C",
|
|
1513
|
+
source: sourceName,
|
|
1514
|
+
key: normalizedPath || undefined
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
function walk(value, path, depth) {
|
|
1519
|
+
if (!value || typeof value !== "object" || depth > 5) {
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
if (Array.isArray(value)) {
|
|
1524
|
+
value.forEach((entry, index) => walk(entry, `${path}[${index}]`, depth + 1));
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
const objectName = firstNonEmptyString([
|
|
1529
|
+
value.name,
|
|
1530
|
+
value.label,
|
|
1531
|
+
value.type,
|
|
1532
|
+
value.sensor,
|
|
1533
|
+
value.description
|
|
1534
|
+
]);
|
|
1535
|
+
const objectDescriptor = firstNonEmptyString([
|
|
1536
|
+
value.type,
|
|
1537
|
+
value.sensor,
|
|
1538
|
+
value.category,
|
|
1539
|
+
value.metric,
|
|
1540
|
+
value.kind,
|
|
1541
|
+
objectName
|
|
1542
|
+
]);
|
|
1543
|
+
const objectUnit = firstNonEmptyString([
|
|
1544
|
+
value.unit,
|
|
1545
|
+
value.units,
|
|
1546
|
+
value.scale
|
|
1547
|
+
]);
|
|
1548
|
+
if ((objectName && isTemperatureKey(objectName)) || isTemperatureKey(objectDescriptor) || isTemperatureKey(path)) {
|
|
1549
|
+
[
|
|
1550
|
+
value.value,
|
|
1551
|
+
value.current,
|
|
1552
|
+
value.currentValue,
|
|
1553
|
+
value.temperature,
|
|
1554
|
+
value.temp
|
|
1555
|
+
].forEach((candidate) => addReading(objectName || objectDescriptor, candidate, objectUnit, objectDescriptor || objectName, path));
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
Object.entries(value).forEach(([key, entryValue]) => {
|
|
1559
|
+
const entryPath = path ? `${path}.${key}` : key;
|
|
1560
|
+
const keyLooksLikeTemperature = isTemperatureKey(key);
|
|
1561
|
+
if (keyLooksLikeTemperature) {
|
|
1562
|
+
if (entryValue && typeof entryValue === "object") {
|
|
1563
|
+
const nestedUnit = firstNonEmptyString([
|
|
1564
|
+
entryValue.unit,
|
|
1565
|
+
entryValue.units,
|
|
1566
|
+
entryValue.scale,
|
|
1567
|
+
objectUnit
|
|
1568
|
+
]);
|
|
1569
|
+
[
|
|
1570
|
+
entryValue.value,
|
|
1571
|
+
entryValue.current,
|
|
1572
|
+
entryValue.currentValue,
|
|
1573
|
+
entryValue.celsius,
|
|
1574
|
+
entryValue.c,
|
|
1575
|
+
entryValue.temperature,
|
|
1576
|
+
entryValue.temp
|
|
1577
|
+
].forEach((candidate) => addReading(objectName || key, candidate, nestedUnit, key, entryPath));
|
|
1578
|
+
} else {
|
|
1579
|
+
addReading(objectName || key, entryValue, objectUnit, key, entryPath);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
if (entryValue && typeof entryValue === "object") {
|
|
1584
|
+
walk(entryValue, entryPath, depth + 1);
|
|
1585
|
+
}
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
walk(source, "", 0);
|
|
1590
|
+
return readings;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
function buildSelectedDeviceKeySet(deviceId, device) {
|
|
1594
|
+
const scopedDevice = resolveScopedIdentifiers("device", deviceId, device);
|
|
1595
|
+
const selectedDevice = device && typeof device === "object" && !Array.isArray(device)
|
|
1596
|
+
? device
|
|
1597
|
+
: {};
|
|
1598
|
+
const selectedDeviceKeys = new Set();
|
|
1599
|
+
[
|
|
1600
|
+
scopedDevice.resourceId,
|
|
1601
|
+
selectedDevice.id,
|
|
1602
|
+
selectedDevice.deviceId,
|
|
1603
|
+
selectedDevice.device_id,
|
|
1604
|
+
selectedDevice._id,
|
|
1605
|
+
selectedDevice.macAddress,
|
|
1606
|
+
selectedDevice.mac,
|
|
1607
|
+
selectedDevice.mac_address,
|
|
1608
|
+
selectedDevice.serial,
|
|
1609
|
+
selectedDevice.serialNumber
|
|
1610
|
+
].forEach((value) => addIdentifierKeys(selectedDeviceKeys, value));
|
|
1611
|
+
return {
|
|
1612
|
+
scopedDevice,
|
|
1613
|
+
selectedDevice,
|
|
1614
|
+
selectedDeviceKeys
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function findMatchingLegacyDevice(legacyDevices, selectedDeviceKeys) {
|
|
1619
|
+
return (Array.isArray(legacyDevices) ? legacyDevices : []).find((legacyDevice) => {
|
|
1620
|
+
return [
|
|
1621
|
+
legacyDevice && legacyDevice.device_id,
|
|
1622
|
+
legacyDevice && legacyDevice.id,
|
|
1623
|
+
legacyDevice && legacyDevice._id,
|
|
1624
|
+
legacyDevice && legacyDevice.mac,
|
|
1625
|
+
legacyDevice && legacyDevice.macAddress,
|
|
1626
|
+
legacyDevice && legacyDevice.serial,
|
|
1627
|
+
legacyDevice && legacyDevice.serialNumber
|
|
1628
|
+
].some((value) => {
|
|
1629
|
+
const rawKey = normalizeString(value).toLowerCase();
|
|
1630
|
+
const compactKey = normalizeIdentifierKey(value);
|
|
1631
|
+
return selectedDeviceKeys.has(rawKey) || selectedDeviceKeys.has(compactKey);
|
|
1632
|
+
});
|
|
1633
|
+
}) || null;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
node.fetchDeviceTemperatures = async (deviceId) => {
|
|
1637
|
+
const device = await node.fetchDeviceByTypeAndId("device", deviceId);
|
|
1638
|
+
const {
|
|
1639
|
+
scopedDevice,
|
|
1640
|
+
selectedDevice,
|
|
1641
|
+
selectedDeviceKeys
|
|
1642
|
+
} = buildSelectedDeviceKeySet(deviceId, device);
|
|
1643
|
+
|
|
1644
|
+
const sources = [];
|
|
1645
|
+
const officialReadings = collectTemperatureReadings(device, "official");
|
|
1646
|
+
if (officialReadings.length > 0) {
|
|
1647
|
+
sources.push("official");
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
let legacyDevice = null;
|
|
1651
|
+
let legacyReadings = [];
|
|
1652
|
+
if (scopedDevice.siteId) {
|
|
1653
|
+
try {
|
|
1654
|
+
const legacyDevices = await fetchLegacyDevices(scopedDevice.siteId);
|
|
1655
|
+
legacyDevice = findMatchingLegacyDevice(legacyDevices, selectedDeviceKeys);
|
|
1656
|
+
legacyReadings = collectTemperatureReadings(legacyDevice, "legacy");
|
|
1657
|
+
if (legacyReadings.length > 0) {
|
|
1658
|
+
sources.push("legacy");
|
|
1659
|
+
}
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
legacyDevice = null;
|
|
1662
|
+
legacyReadings = [];
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
const dedupe = new Set();
|
|
1667
|
+
const temperatures = officialReadings.concat(legacyReadings).filter((reading) => {
|
|
1668
|
+
const key = `${normalizeString(reading.name).toLowerCase()}:${reading.valueC}`;
|
|
1669
|
+
if (dedupe.has(key)) {
|
|
1670
|
+
return false;
|
|
1671
|
+
}
|
|
1672
|
+
dedupe.add(key);
|
|
1673
|
+
return true;
|
|
1674
|
+
});
|
|
1675
|
+
const maxTemperatureC = temperatures.reduce((max, reading) => {
|
|
1676
|
+
const value = Number(reading && reading.valueC);
|
|
1677
|
+
if (!Number.isFinite(value)) {
|
|
1678
|
+
return max;
|
|
1679
|
+
}
|
|
1680
|
+
return Number.isFinite(max) ? Math.max(max, value) : value;
|
|
1681
|
+
}, NaN);
|
|
1682
|
+
const primaryTemperatureC = temperatures.length > 0
|
|
1683
|
+
? Number(temperatures[0].valueC)
|
|
1684
|
+
: NaN;
|
|
1685
|
+
const deviceName = firstNonEmptyString([
|
|
1686
|
+
selectedDevice.name,
|
|
1687
|
+
selectedDevice.displayName,
|
|
1688
|
+
selectedDevice.hostname,
|
|
1689
|
+
legacyDevice && legacyDevice.name,
|
|
1690
|
+
legacyDevice && legacyDevice.hostname,
|
|
1691
|
+
scopedDevice.resourceId
|
|
1692
|
+
]);
|
|
1693
|
+
|
|
1694
|
+
return {
|
|
1695
|
+
device: {
|
|
1696
|
+
...selectedDevice,
|
|
1697
|
+
...(legacyDevice ? { legacyDevice } : {})
|
|
1698
|
+
},
|
|
1699
|
+
sources,
|
|
1700
|
+
payload: {
|
|
1701
|
+
deviceId,
|
|
1702
|
+
siteId: scopedDevice.siteId || undefined,
|
|
1703
|
+
resourceId: scopedDevice.resourceId || undefined,
|
|
1704
|
+
deviceName: deviceName || undefined,
|
|
1705
|
+
hasTemperatures: temperatures.length > 0,
|
|
1706
|
+
temperatureC: Number.isFinite(primaryTemperatureC) ? primaryTemperatureC : undefined,
|
|
1707
|
+
maxTemperatureC: Number.isFinite(maxTemperatureC) ? maxTemperatureC : undefined,
|
|
1708
|
+
temperatures
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1425
1713
|
node.fetchDevicePorts = async (deviceId) => {
|
|
1426
1714
|
const device = await node.fetchDeviceByTypeAndId("device", deviceId);
|
|
1427
1715
|
const ports = extractDevicePorts(device);
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
deviceId: { value: "", required: true },
|
|
14
14
|
deviceName: { value: "" },
|
|
15
15
|
portIdx: { value: 1, required: true, validate: RED.validators.number() },
|
|
16
|
-
action: { value: "msgPayload", required: true }
|
|
17
|
-
timeout: { value: 15000, required: true, validate: RED.validators.number() }
|
|
16
|
+
action: { value: "msgPayload", required: true }
|
|
18
17
|
},
|
|
19
18
|
inputs: 1,
|
|
20
19
|
outputs: 1,
|
|
@@ -1095,10 +1094,6 @@
|
|
|
1095
1094
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
1096
1095
|
<input type="text" id="node-input-name" placeholder="Node name">
|
|
1097
1096
|
</div>
|
|
1098
|
-
<div class="form-row">
|
|
1099
|
-
<label for="node-input-timeout"><i class="fa fa-clock-o"></i> Timeout</label>
|
|
1100
|
-
<input type="text" id="node-input-timeout" placeholder="15000">
|
|
1101
|
-
</div>
|
|
1102
1097
|
<input type="hidden" id="node-input-deviceName">
|
|
1103
1098
|
</div>
|
|
1104
1099
|
</script>
|
|
@@ -1116,8 +1111,8 @@
|
|
|
1116
1111
|
<p><b>Port</b> selects the physical port index. Port labels include connected clients or downstream UniFi devices when available.</p>
|
|
1117
1112
|
<p><b>Action</b> executes the configured PoE operation. <code>POE controlled by msg.payload</code> maps incoming payloads to PoE mode (<code>true</code> enables PoE, <code>false</code> disables PoE). Enable and Disable update the UniFi port override (<code>poe_mode</code> auto/off). Power Cycle uses the official Network port action. <code>Emit Power Consumption</code> emits power values from the shared observer in the config node.</p>
|
|
1118
1113
|
<p><b>Power poll interval</b> for emit action is configured globally in <code>Unifi Network Config</code>. This node does not run its own timer.</p>
|
|
1114
|
+
<p>Request timeout is handled automatically by the node.</p>
|
|
1119
1115
|
<p><b>Name</b> is the node name shown in the editor and is updated only when you manually select a different switch or client target.</p>
|
|
1120
|
-
<p><b>Timeout</b> controls the request timeout in milliseconds.</p>
|
|
1121
1116
|
|
|
1122
1117
|
<h3>Input</h3>
|
|
1123
1118
|
<ul>
|
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
resolveScopedIdentifiers
|
|
6
6
|
} = require("./utils/unifi-network-device-registry");
|
|
7
7
|
const { extractNetworkData } = require("./utils/unifi-network-utils");
|
|
8
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
|
|
8
9
|
|
|
9
10
|
function normalizeString(value) {
|
|
10
11
|
return String(value || "").trim();
|
|
@@ -248,7 +249,7 @@ module.exports = function(RED) {
|
|
|
248
249
|
node.deviceName = resolveDeviceName(config.deviceName);
|
|
249
250
|
node.portIdx = config.portIdx;
|
|
250
251
|
node.action = config.action || "msgPayload";
|
|
251
|
-
node.timeout =
|
|
252
|
+
node.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
252
253
|
node.isPowerObserving = false;
|
|
253
254
|
node.lastObservedPowerW = undefined;
|
|
254
255
|
node.hasObservedPower = false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<link rel="stylesheet" type="text/css"
|
|
1
|
+
<link rel="stylesheet" type="text/css"
|
|
2
|
+
href="resources/node-red-contrib-unifi-ultimate/editor/unifi-ultimate-editor-common.css">
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
<script type="text/javascript">
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
inputs: { value: 1 },
|
|
15
16
|
capability: { value: "observe", required: true },
|
|
16
17
|
capabilityConfig: { value: "{}" },
|
|
17
|
-
|
|
18
|
+
autoEmit: { value: false },
|
|
19
|
+
autoEmitInterval: { value: 60, validate: RED.validators.number() }
|
|
18
20
|
},
|
|
19
21
|
inputs: 1,
|
|
20
22
|
outputs: 1,
|
|
@@ -27,8 +29,11 @@
|
|
|
27
29
|
oneditsave: function () {
|
|
28
30
|
const selectedCapabilityOpensStream = $("#node-input-capability option:selected").data("opens-stream") === true
|
|
29
31
|
|| $("#node-input-capability option:selected").attr("data-opens-stream") === "true";
|
|
32
|
+
const selectedCapabilityMethod = String($("#node-input-capability option:selected").data("method") || $("#node-input-capability option:selected").attr("data-method") || "").trim().toUpperCase();
|
|
33
|
+
const supportsPeriodicEmit = !selectedCapabilityOpensStream && selectedCapabilityMethod !== "POST";
|
|
30
34
|
// Hide the input pin only when the selected action starts an event stream.
|
|
31
35
|
this.inputs = selectedCapabilityOpensStream ? 0 : 1;
|
|
36
|
+
this.autoEmit = supportsPeriodicEmit ? $("#node-input-autoEmit").is(":checked") : false;
|
|
32
37
|
|
|
33
38
|
const $capabilityConfig = $("#node-input-capabilityConfig");
|
|
34
39
|
const capabilityConfig = {};
|
|
@@ -84,6 +89,10 @@
|
|
|
84
89
|
const $capabilityConfig = $("#node-input-capabilityConfig");
|
|
85
90
|
const $capabilityConfigRow = $("#node-row-capabilityConfig");
|
|
86
91
|
const $capabilityConfigContainer = $("#node-input-capabilityConfigContainer");
|
|
92
|
+
const $autoEmit = $("#node-input-autoEmit");
|
|
93
|
+
const $autoEmitInterval = $("#node-input-autoEmitInterval");
|
|
94
|
+
const $autoEmitRow = $("#node-row-autoEmit");
|
|
95
|
+
const $autoEmitIntervalRow = $("#node-row-autoEmitInterval");
|
|
87
96
|
const $refresh = $("#node-input-refreshDevices");
|
|
88
97
|
const $deviceTypeRow = $deviceType.closest(".form-row");
|
|
89
98
|
const $deviceIdRow = $deviceId.closest(".form-row");
|
|
@@ -94,6 +103,7 @@
|
|
|
94
103
|
let capabilityOptionsRequestId = 0;
|
|
95
104
|
let suspendChangeHandling = false;
|
|
96
105
|
let isInitializingEditor = true;
|
|
106
|
+
let restoredPersistedAutoEmit = false;
|
|
97
107
|
let deviceTypeDefinitions = [];
|
|
98
108
|
let capabilityDefinitions = [];
|
|
99
109
|
let clientTargetsLoading = false;
|
|
@@ -110,12 +120,29 @@
|
|
|
110
120
|
const hasDevice = hasSelection($deviceId);
|
|
111
121
|
const hasCapability = hasSelection($capability);
|
|
112
122
|
const hasCapabilityFields = $capabilityConfigRow.data("has-fields") === true;
|
|
123
|
+
const capabilityDefinition = getSelectedCapabilityDefinition();
|
|
124
|
+
const supportsPeriodicEmit = capabilityDefinition
|
|
125
|
+
&& capabilityDefinition.opensEventStream !== true
|
|
126
|
+
&& String(capabilityDefinition.method || "").trim().toUpperCase() !== "POST";
|
|
127
|
+
const showPeriodicEmit = Boolean(hasServer && hasDeviceType && hasDevice && hasCapability && supportsPeriodicEmit);
|
|
113
128
|
|
|
114
129
|
$deviceTypeRow.toggle(hasServer);
|
|
115
130
|
$deviceIdRow.toggle(hasServer && hasDeviceType);
|
|
116
131
|
$capabilityRow.toggle(hasServer && hasDeviceType && hasDevice);
|
|
117
132
|
$capabilityConfigRow.toggle(hasServer && hasDeviceType && hasDevice && hasCapability && hasCapabilityFields);
|
|
118
133
|
$advancedRow.toggle(hasServer && hasDeviceType && hasDevice && hasCapability);
|
|
134
|
+
$autoEmitRow.toggle(showPeriodicEmit);
|
|
135
|
+
$autoEmitIntervalRow.toggle(showPeriodicEmit && $autoEmit.is(":checked"));
|
|
136
|
+
|
|
137
|
+
if (showPeriodicEmit && !restoredPersistedAutoEmit) {
|
|
138
|
+
$autoEmit.prop("checked", node.autoEmit === true || node.autoEmit === "true");
|
|
139
|
+
restoredPersistedAutoEmit = true;
|
|
140
|
+
$autoEmitIntervalRow.toggle($autoEmit.is(":checked"));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!showPeriodicEmit && !isInitializingEditor) {
|
|
144
|
+
$autoEmit.prop("checked", false);
|
|
145
|
+
}
|
|
119
146
|
}
|
|
120
147
|
|
|
121
148
|
function parseCapabilityConfig(rawValue) {
|
|
@@ -521,10 +548,34 @@
|
|
|
521
548
|
return "Loading clients from " + normalizedDeviceName + ".";
|
|
522
549
|
}
|
|
523
550
|
|
|
551
|
+
if (normalizedLabel === "Count Online Clients") {
|
|
552
|
+
return "Counting online clients in " + normalizedDeviceName + ".";
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (normalizedLabel === "Create Guest Voucher") {
|
|
556
|
+
return "Creating a guest voucher for " + normalizedDeviceName + ".";
|
|
557
|
+
}
|
|
558
|
+
|
|
524
559
|
if (normalizedLabel === "Read Application Info") {
|
|
525
560
|
return "Reading UniFi Network application information.";
|
|
526
561
|
}
|
|
527
562
|
|
|
563
|
+
if (normalizedLabel === "Read Temperatures") {
|
|
564
|
+
return "Reading switch temperature sensors from " + normalizedDeviceName + ".";
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (normalizedLabel === "Read CPU") {
|
|
568
|
+
return "Reading CPU usage from " + normalizedDeviceName + ".";
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (normalizedLabel === "Read Memory") {
|
|
572
|
+
return "Reading memory usage from " + normalizedDeviceName + ".";
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (normalizedLabel === "Read Uptime") {
|
|
576
|
+
return "Reading uptime from " + normalizedDeviceName + ".";
|
|
577
|
+
}
|
|
578
|
+
|
|
528
579
|
if (normalizedLabel === "Restart Device") {
|
|
529
580
|
return "Restarting " + normalizedDeviceName + ".";
|
|
530
581
|
}
|
|
@@ -537,6 +588,10 @@
|
|
|
537
588
|
return "Authorizing guest access for " + normalizedDeviceName + ".";
|
|
538
589
|
}
|
|
539
590
|
|
|
591
|
+
if (normalizedLabel === "Is Client Online") {
|
|
592
|
+
return "Checking whether " + normalizedDeviceName + " is online.";
|
|
593
|
+
}
|
|
594
|
+
|
|
540
595
|
if (normalizedLabel === "Revoke Guest Access") {
|
|
541
596
|
return "Revoking guest access for " + normalizedDeviceName + ".";
|
|
542
597
|
}
|
|
@@ -630,6 +685,7 @@
|
|
|
630
685
|
$("<option></option>")
|
|
631
686
|
.val(item.id)
|
|
632
687
|
.attr("data-mode", String(item.mode || "").trim())
|
|
688
|
+
.attr("data-method", String(item.method || "").trim())
|
|
633
689
|
.attr("data-opens-stream", item.opensEventStream === true ? "true" : "false")
|
|
634
690
|
.text(item.label)
|
|
635
691
|
);
|
|
@@ -1132,6 +1188,9 @@
|
|
|
1132
1188
|
writeCapabilityConfig();
|
|
1133
1189
|
refreshAfterCapabilityChange();
|
|
1134
1190
|
});
|
|
1191
|
+
$autoEmit.on("change", function () {
|
|
1192
|
+
syncProgressiveRows();
|
|
1193
|
+
});
|
|
1135
1194
|
$refresh.on("click", function (event) {
|
|
1136
1195
|
event.preventDefault();
|
|
1137
1196
|
refreshAfterServerChange();
|
|
@@ -1185,9 +1244,15 @@
|
|
|
1185
1244
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
1186
1245
|
<input type="text" id="node-input-name" placeholder="Node name">
|
|
1187
1246
|
</div>
|
|
1188
|
-
<div class="form-row">
|
|
1189
|
-
<label for="node-input-
|
|
1190
|
-
<input type="
|
|
1247
|
+
<div class="form-row" id="node-row-autoEmit">
|
|
1248
|
+
<label for="node-input-autoEmit"><i class="fa fa-repeat"></i> Repeat</label>
|
|
1249
|
+
<input type="checkbox" id="node-input-autoEmit" style="display:inline-block; width:auto; vertical-align:top;">
|
|
1250
|
+
<span style="margin-left:8px;">Emit periodically</span>
|
|
1251
|
+
</div>
|
|
1252
|
+
<div class="form-row" id="node-row-autoEmitInterval">
|
|
1253
|
+
<label for="node-input-autoEmitInterval"><i class="fa fa-clock-o"></i> Every</label>
|
|
1254
|
+
<input type="number" id="node-input-autoEmitInterval" min="5" step="1" placeholder="60" style="width:120px;">
|
|
1255
|
+
<span style="margin-left:8px;">seconds</span>
|
|
1191
1256
|
</div>
|
|
1192
1257
|
</div>
|
|
1193
1258
|
</script>
|
|
@@ -1202,11 +1267,18 @@
|
|
|
1202
1267
|
<p><b>Resource</b> chooses what you want to work with: Site, UniFi Device, or Client.</p>
|
|
1203
1268
|
<p><b>Item</b> chooses the specific site, device, or client. Device and client selectors are searchable and open with the complete list before filtering.</p>
|
|
1204
1269
|
<p><b>Action</b> only shows actions supported by the selected resource. Additional fields appear only when the selected action needs extra input.</p>
|
|
1205
|
-
<p>Action highlights include <code>
|
|
1270
|
+
<p>Action highlights include <code>Count Online Clients</code>, <code>Create Guest Voucher</code>, <code>Read CPU</code>, <code>Read Memory</code>, <code>Read Uptime</code>, <code>Read Temperatures</code>, <code>Is Client Online</code>, <code>Restart Device</code>, and <code>Power Cycle Port</code>.</p>
|
|
1206
1271
|
<p><code>Read Application Info</code> is available on the <code>Site</code> resource type and returns Network application metadata.</p>
|
|
1272
|
+
<p><code>Count Online Clients</code> emits the number of online clients as <code>msg.payload</code>. Full client details are available in <code>msg.details.clients</code> and <code>msg.details.onlineClients</code>.</p>
|
|
1273
|
+
<p><code>Create Guest Voucher</code> emits the voucher code as <code>msg.payload</code> when one voucher is created, or an array of codes when more than one is created. Full voucher details are available in <code>msg.details.vouchers</code>.</p>
|
|
1274
|
+
<p><code>Read CPU</code>, <code>Read Memory</code>, and <code>Read Uptime</code> emit a single number as <code>msg.payload</code>. Full statistics are available in <code>msg.details.statistics</code>.</p>
|
|
1275
|
+
<p><code>Read Temperatures</code> is available on <code>UniFi Device</code> resources. It emits the temperature in Celsius as <code>msg.payload</code> when the selected switch/controller exposes thermal sensor data. More details are available in <code>msg.details.temperature</code>. Some UniFi models do not report temperatures.</p>
|
|
1276
|
+
<p><code>Is Client Online</code> emits <code>true</code> or <code>false</code> as <code>msg.payload</code>. Full client details are available in <code>msg.details.client</code>.</p>
|
|
1207
1277
|
<p><code>Receive Events (Unofficial Stream)</code> uses a non-official websocket endpoint and is marked experimental. The websocket is opened once by the shared Network config node and events are fanned out to subscribed runtime nodes. In this mode, only <code>All</code> is available and the node emits all received Network events because fine-grained filtering is not currently available.</p>
|
|
1208
1278
|
<p>When selecting a switch port, the port list shows connected clients or downstream UniFi devices when the controller exposes that information.</p>
|
|
1209
|
-
<p><b>
|
|
1279
|
+
<p><b>Emit periodically</b> repeats read-only actions at the selected interval and sends each result to the flow. It is hidden for event streams and write actions such as restart, PoE power-cycle, guest authorization, and voucher creation.</p>
|
|
1280
|
+
<p>Request timeout is handled automatically by the node.</p>
|
|
1281
|
+
<p><b>Name</b> is the node name shown in the editor and is updated only when you manually select a different item from the list.</p>
|
|
1210
1282
|
|
|
1211
1283
|
<h3>Input</h3>
|
|
1212
1284
|
<ul>
|