node-red-contrib-unifi-ultimate 1.1.2 → 1.1.4
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 +10 -0
- package/nodes/unifi-access-config.js +20 -4
- package/nodes/unifi-access-device.html +20 -4
- package/nodes/unifi-network-config.js +156 -8
- package/nodes/unifi-network-device.html +34 -8
- package/nodes/unifi-network-presence.html +159 -34
- package/nodes/unifi-network-presence.js +26 -0
- package/nodes/unifi-network-restart.html +43 -11
- package/nodes/unifi-protect-device.html +20 -4
- package/nodes/utils/unifi-access-device-registry.js +100 -4
- package/nodes/utils/unifi-network-presence-utils.js +117 -0
- package/nodes/utils/unifi-protect-device-registry.js +225 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -78,6 +78,7 @@ Use **Network** nodes to work with:
|
|
|
78
78
|
Things you can do:
|
|
79
79
|
|
|
80
80
|
- Check whether a device or phone is connected to your network.
|
|
81
|
+
- Track presence either by the exact UniFi client ID or by client name; name matching tolerates private/rotating MAC addresses by resolving the active client again on every poll.
|
|
81
82
|
- Re-send the current presence state at a fixed interval with the Presence node's **Resend** field (e.g. to keep a dashboard or home-automation system in sync).
|
|
82
83
|
- Count how many clients are currently online.
|
|
83
84
|
- List the site's configured networks, Wi-Fi broadcasts, and WAN interfaces.
|
|
@@ -108,6 +109,9 @@ Use **Protect** nodes to work with:
|
|
|
108
109
|
- lights
|
|
109
110
|
- chimes
|
|
110
111
|
- viewers
|
|
112
|
+
- bridges and Link Stations
|
|
113
|
+
- alarm hubs and key fobs
|
|
114
|
+
- sirens, relays, and speakers
|
|
111
115
|
- NVR
|
|
112
116
|
|
|
113
117
|
Things you can do:
|
|
@@ -118,6 +122,8 @@ Things you can do:
|
|
|
118
122
|
- Control PTZ cameras (move to preset, start/stop patrol).
|
|
119
123
|
- Display a custom message on a doorbell screen.
|
|
120
124
|
- Switch a viewer to a different live feed.
|
|
125
|
+
- Monitor bridges, Link Stations, alarm hubs, key fobs, sirens, relays, and speakers.
|
|
126
|
+
- Play or stop a siren, control relay outputs, and test speaker or siren sound.
|
|
121
127
|
|
|
122
128
|
<br/>
|
|
123
129
|
<br/>
|
|
@@ -133,6 +139,8 @@ Use **Access** nodes to work with:
|
|
|
133
139
|
- Access devices (hubs, intercoms)
|
|
134
140
|
- door events (unlock, ring, DPS, emergency)
|
|
135
141
|
- lock rules and schedules
|
|
142
|
+
- visitors, access policies, holiday groups, and door groups
|
|
143
|
+
- recent system logs
|
|
136
144
|
- doorbell actions
|
|
137
145
|
|
|
138
146
|
Things you can do:
|
|
@@ -142,6 +150,8 @@ Things you can do:
|
|
|
142
150
|
- Enable lockdown or evacuation mode.
|
|
143
151
|
- Receive door events in real time.
|
|
144
152
|
- Trigger or cancel an intercom doorbell.
|
|
153
|
+
- Read visitors, access policies, schedules, holiday groups, and door groups.
|
|
154
|
+
- Inspect recent Access system-log entries and the door-group topology.
|
|
145
155
|
|
|
146
156
|
## Outputs
|
|
147
157
|
|
|
@@ -133,19 +133,35 @@ module.exports = function(RED) {
|
|
|
133
133
|
throw new Error(`Unsupported device type: ${deviceType}`);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
const listMethod = String(definition.listMethod || "GET").toUpperCase();
|
|
137
|
+
const listPayload = typeof definition.listPayload === "function"
|
|
138
|
+
? definition.listPayload()
|
|
139
|
+
: definition.listPayload;
|
|
136
140
|
const response = await node.apiRequest({
|
|
137
141
|
path: definition.listPath,
|
|
138
|
-
method:
|
|
142
|
+
method: listMethod,
|
|
139
143
|
// Some Access device inventories only refresh reliably when this
|
|
140
144
|
// query flag is present.
|
|
141
|
-
query:
|
|
145
|
+
query: {
|
|
146
|
+
...(definition.listQuery && typeof definition.listQuery === "object" ? definition.listQuery : {}),
|
|
147
|
+
...(deviceType === "device" ? { refresh: "true" } : {})
|
|
148
|
+
},
|
|
149
|
+
payload: listMethod === "GET" || listMethod === "HEAD" ? undefined : listPayload
|
|
142
150
|
});
|
|
143
151
|
|
|
144
152
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
145
153
|
throw new Error(`Failed to load ${deviceType} entries (${response.statusCode})`);
|
|
146
154
|
}
|
|
147
155
|
|
|
148
|
-
|
|
156
|
+
let collectionPayload = extractAccessData(response.payload);
|
|
157
|
+
if (definition.collectionPath) {
|
|
158
|
+
collectionPayload = String(definition.collectionPath)
|
|
159
|
+
.split(".")
|
|
160
|
+
.filter(Boolean)
|
|
161
|
+
.reduce((current, key) => current && typeof current === "object" ? current[key] : undefined, collectionPayload);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return normalizeAccessCollection(collectionPayload);
|
|
149
165
|
};
|
|
150
166
|
|
|
151
167
|
node.fetchDeviceByTypeAndId = async (deviceType, deviceId) => {
|
|
@@ -170,7 +186,7 @@ module.exports = function(RED) {
|
|
|
170
186
|
}
|
|
171
187
|
|
|
172
188
|
const items = await node.fetchDevices(deviceType);
|
|
173
|
-
return items.find((entry) => String(entry.id || "").trim() === String(deviceId || "").trim()) || null;
|
|
189
|
+
return items.find((entry) => String(entry.id || entry._id || "").trim() === String(deviceId || "").trim()) || null;
|
|
174
190
|
};
|
|
175
191
|
|
|
176
192
|
node.fetchCapabilityOptions = async (deviceType, deviceId, capabilityId, capabilityConfig) => {
|
|
@@ -850,7 +850,20 @@
|
|
|
850
850
|
);
|
|
851
851
|
});
|
|
852
852
|
|
|
853
|
-
|
|
853
|
+
const hasCurrentValue = currentValue && $deviceId.find("option").filter(function () {
|
|
854
|
+
return String($(this).val() || "") === currentValue;
|
|
855
|
+
}).length > 0;
|
|
856
|
+
if (hasCurrentValue) {
|
|
857
|
+
$deviceId.val(currentValue);
|
|
858
|
+
} else if (currentValue) {
|
|
859
|
+
const savedName = String(node.deviceName || currentValue).trim();
|
|
860
|
+
$deviceId.append(
|
|
861
|
+
$("<option></option>")
|
|
862
|
+
.val(currentValue)
|
|
863
|
+
.text(savedName + " (saved; currently unavailable)")
|
|
864
|
+
.attr("data-device-name", savedName)
|
|
865
|
+
.attr("data-unavailable", "true")
|
|
866
|
+
);
|
|
854
867
|
$deviceId.val(currentValue);
|
|
855
868
|
} else {
|
|
856
869
|
$deviceId.val("");
|
|
@@ -1069,6 +1082,7 @@
|
|
|
1069
1082
|
});
|
|
1070
1083
|
|
|
1071
1084
|
refreshSelectionSummary();
|
|
1085
|
+
renderDevices([]);
|
|
1072
1086
|
ensureDefaultServerSelection();
|
|
1073
1087
|
refreshEditor();
|
|
1074
1088
|
}
|
|
@@ -1135,13 +1149,15 @@
|
|
|
1135
1149
|
|
|
1136
1150
|
<h3>Configuration</h3>
|
|
1137
1151
|
<p><b>Connection</b> selects the shared UniFi Access config node.</p>
|
|
1138
|
-
<p><b>Control</b> chooses the Access category. <b>Device</b> chooses the specific door or
|
|
1152
|
+
<p><b>Control</b> chooses the Access category. <b>Device</b> chooses the specific door, device, visitor, policy, schedule, holiday group, door group, or recent system-log entry. Selectors are searchable and open with the complete list before filtering. A saved selection that is temporarily unavailable is preserved instead of being cleared.</p>
|
|
1139
1153
|
<p><b>Action</b> only shows actions supported by the selected item.</p>
|
|
1140
1154
|
<p>Additional fields appear only when the selected action needs extra input, such as a temporary lock rule or a room name for doorbell actions.</p>
|
|
1141
1155
|
<p>For <code>Set Temporary Lock Rule</code>, choose <code>Custom Duration</code> to reveal the minutes field. Legacy <code>ended_time</code> is still available only as fallback compatibility.</p>
|
|
1142
1156
|
<p><code>Receive Events</code> fetches the current state once and then subscribes to events provided by the shared UniFi Access config node. The config node maintains the official notifications WebSocket and fans out events to runtime nodes. In this mode, <code>All</code> emits every event for the selected device/door, while specific <code>Event</code> choices filter to official UniFi Access event families (for example doorbell, door unlock, DPS, emergency, schedule, and temporary unlock events). The input pin is hidden and listening starts automatically after deploy/restart.</p>
|
|
1143
1157
|
<p><code>Trigger Doorbell</code> and <code>Cancel Doorbell</code> use a manual <code>Room Name</code> field when needed. The node does not currently discover Intercom directory names automatically.</p>
|
|
1144
1158
|
<p><code>Cancel Doorbell</code> uses a shared safe-cancel guard in the UniFi Access config node with a 3 minute tracking window. Tracking is updated by websocket events and a fallback system-log poller.</p>
|
|
1159
|
+
<p>Visitors support state reads and the official visitor-status event. Access policies, schedules, holiday groups, and door groups are read-only. <code>Read Door Group Topology</code> returns the complete hierarchy documented by Access.</p>
|
|
1160
|
+
<p><code>Recent System Log</code> lists entries from the previous 24 hours, up to the first 200 results. It is read-only and requires the token's <code>view:system_log</code> permission.</p>
|
|
1145
1161
|
<p><b>Emit periodically</b> repeats read-only actions at the selected interval and sends each result to the flow. It is hidden for <code>Receive Events</code> and write actions.</p>
|
|
1146
1162
|
<p>Request timeout is handled automatically by the node.</p>
|
|
1147
1163
|
<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>
|
|
@@ -1156,7 +1172,7 @@
|
|
|
1156
1172
|
<h3>Outputs</h3>
|
|
1157
1173
|
<dl class="message-properties">
|
|
1158
1174
|
<dt>Output 1 — result</dt>
|
|
1159
|
-
<dd>Emits state and live event messages for the selected
|
|
1175
|
+
<dd>Emits state and live event messages for the selected Access resource. When <code>Receive Events</code> is active, both state and event messages use this pin.</dd>
|
|
1160
1176
|
<dt class="optional">msg.topic</dt>
|
|
1161
1177
|
<dd>Node name from the editor.</dd>
|
|
1162
1178
|
<dt class="optional">msg.deviceName</dt>
|
|
@@ -1202,4 +1218,4 @@
|
|
|
1202
1218
|
"payload": null,
|
|
1203
1219
|
"error": { "message": "Request timed out" }
|
|
1204
1220
|
}</code></pre>
|
|
1205
|
-
</script>
|
|
1221
|
+
</script>
|
|
@@ -24,6 +24,12 @@ const {
|
|
|
24
24
|
resolveScopedIdentifiers,
|
|
25
25
|
summarizeDevice
|
|
26
26
|
} = require("./utils/unifi-network-device-registry");
|
|
27
|
+
const {
|
|
28
|
+
normalizePresenceMatchBy,
|
|
29
|
+
normalizeClientMatchName,
|
|
30
|
+
findActiveClientsByName,
|
|
31
|
+
resolveClientResourceId
|
|
32
|
+
} = require("./utils/unifi-network-presence-utils");
|
|
27
33
|
|
|
28
34
|
module.exports = function(RED) {
|
|
29
35
|
const API_KEY_HEADER = "X-API-Key";
|
|
@@ -1433,7 +1439,7 @@ module.exports = function(RED) {
|
|
|
1433
1439
|
return node.legacySiteNameById.get(normalizedSiteId) || "";
|
|
1434
1440
|
}
|
|
1435
1441
|
|
|
1436
|
-
async function fetchLegacySiteCollection(siteId, collectionPath) {
|
|
1442
|
+
async function fetchLegacySiteCollection(siteId, collectionPath, timeout) {
|
|
1437
1443
|
const legacySiteName = await fetchLegacySiteName(siteId);
|
|
1438
1444
|
if (!legacySiteName) {
|
|
1439
1445
|
return [];
|
|
@@ -1441,7 +1447,8 @@ module.exports = function(RED) {
|
|
|
1441
1447
|
|
|
1442
1448
|
const response = await node.legacyApiRequest({
|
|
1443
1449
|
path: `/api/s/${encodeURIComponent(legacySiteName)}${collectionPath}`,
|
|
1444
|
-
method: "GET"
|
|
1450
|
+
method: "GET",
|
|
1451
|
+
timeout: Number(timeout) > 0 ? Number(timeout) : 15000
|
|
1445
1452
|
});
|
|
1446
1453
|
|
|
1447
1454
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
@@ -1451,8 +1458,8 @@ module.exports = function(RED) {
|
|
|
1451
1458
|
return normalizeNetworkCollection(response.payload);
|
|
1452
1459
|
}
|
|
1453
1460
|
|
|
1454
|
-
async function fetchLegacyClients(siteId) {
|
|
1455
|
-
const clients = await fetchLegacySiteCollection(siteId, "/stat/sta");
|
|
1461
|
+
async function fetchLegacyClients(siteId, timeout) {
|
|
1462
|
+
const clients = await fetchLegacySiteCollection(siteId, "/stat/sta", timeout);
|
|
1456
1463
|
return clients.map((client) => ({
|
|
1457
1464
|
...client,
|
|
1458
1465
|
__unifiUltimateOnline: true,
|
|
@@ -2503,11 +2510,126 @@ module.exports = function(RED) {
|
|
|
2503
2510
|
};
|
|
2504
2511
|
};
|
|
2505
2512
|
|
|
2513
|
+
node.fetchActivePresenceClients = async (siteId, timeout) => {
|
|
2514
|
+
const normalizedSiteId = normalizeString(siteId);
|
|
2515
|
+
if (!normalizedSiteId) {
|
|
2516
|
+
throw new Error("Client selection is invalid. Re-select the client from the editor.");
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
// Name matching needs the currently connected population, not the
|
|
2520
|
+
// historical known-client list. Query both sources so aliases and
|
|
2521
|
+
// hostnames remain available across controller/API versions.
|
|
2522
|
+
const results = await Promise.allSettled([
|
|
2523
|
+
node.fetchPagedCollection({
|
|
2524
|
+
path: `/v1/sites/${encodeURIComponent(normalizedSiteId)}/clients`,
|
|
2525
|
+
timeout: Number(timeout) > 0 ? Number(timeout) : 8000
|
|
2526
|
+
}),
|
|
2527
|
+
fetchLegacyClients(normalizedSiteId, Number(timeout) > 0 ? Number(timeout) : 8000)
|
|
2528
|
+
]);
|
|
2529
|
+
const successful = results.filter((result) => result.status === "fulfilled");
|
|
2530
|
+
if (successful.length === 0) {
|
|
2531
|
+
const firstFailure = results.find((result) => result.status === "rejected");
|
|
2532
|
+
throw (firstFailure && firstFailure.reason) || new Error("Unable to load active clients.");
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
const officialClients = results[0].status === "fulfilled" && Array.isArray(results[0].value)
|
|
2536
|
+
? results[0].value
|
|
2537
|
+
: [];
|
|
2538
|
+
const legacyClients = results[1].status === "fulfilled" && Array.isArray(results[1].value)
|
|
2539
|
+
? results[1].value
|
|
2540
|
+
: [];
|
|
2541
|
+
|
|
2542
|
+
return officialClients
|
|
2543
|
+
.map((client) => ({
|
|
2544
|
+
...client,
|
|
2545
|
+
siteId: client && (client.siteId || client.site_id) || normalizedSiteId,
|
|
2546
|
+
isOnline: true,
|
|
2547
|
+
online: true,
|
|
2548
|
+
offline: false
|
|
2549
|
+
}))
|
|
2550
|
+
.concat(legacyClients.map((client) => ({
|
|
2551
|
+
...client,
|
|
2552
|
+
siteId: client && (client.siteId || client.site_id) || normalizedSiteId,
|
|
2553
|
+
isOnline: true,
|
|
2554
|
+
online: true,
|
|
2555
|
+
offline: false
|
|
2556
|
+
})));
|
|
2557
|
+
};
|
|
2558
|
+
|
|
2559
|
+
node.fetchPresenceObservationSnapshotByName = async (clientId, clientName, timeout, activeClients) => {
|
|
2560
|
+
const scoped = resolveScopedIdentifiers("client", clientId);
|
|
2561
|
+
const normalizedClientName = normalizeString(clientName);
|
|
2562
|
+
if (!scoped.siteId || !normalizedClientName) {
|
|
2563
|
+
throw new Error("Client name selection is invalid. Re-select the client from the editor.");
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
const clients = Array.isArray(activeClients)
|
|
2567
|
+
? activeClients
|
|
2568
|
+
: await node.fetchActivePresenceClients(scoped.siteId, timeout);
|
|
2569
|
+
const matches = findActiveClientsByName(clients, normalizedClientName);
|
|
2570
|
+
if (matches.length === 0) {
|
|
2571
|
+
return {
|
|
2572
|
+
found: false,
|
|
2573
|
+
connected: false,
|
|
2574
|
+
statusCode: 404,
|
|
2575
|
+
client: null,
|
|
2576
|
+
matchBy: "name",
|
|
2577
|
+
clientName: normalizedClientName,
|
|
2578
|
+
matchCount: 0
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
// The official and legacy collections can describe the same active
|
|
2583
|
+
// client. Count unique identities so metadata is not inflated.
|
|
2584
|
+
const uniqueMatches = new Map();
|
|
2585
|
+
matches.forEach((client, index) => {
|
|
2586
|
+
const key = normalizeIdentifierKey(client && (client.macAddress || client.mac_address || client.mac))
|
|
2587
|
+
|| normalizeIdentifierKey(resolveClientResourceId(client))
|
|
2588
|
+
|| String(index);
|
|
2589
|
+
if (!uniqueMatches.has(key)) {
|
|
2590
|
+
uniqueMatches.set(key, client);
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
const matchedClient = uniqueMatches.values().next().value;
|
|
2594
|
+
const matchedResourceId = resolveClientResourceId(matchedClient);
|
|
2595
|
+
const matchedClientId = encodeScopedDeviceId(scoped.siteId, matchedResourceId) || matchedResourceId;
|
|
2596
|
+
|
|
2597
|
+
return {
|
|
2598
|
+
found: true,
|
|
2599
|
+
connected: true,
|
|
2600
|
+
statusCode: 200,
|
|
2601
|
+
client: {
|
|
2602
|
+
...matchedClient,
|
|
2603
|
+
siteId: matchedClient && (matchedClient.siteId || matchedClient.site_id) || scoped.siteId
|
|
2604
|
+
},
|
|
2605
|
+
matchBy: "name",
|
|
2606
|
+
clientName: normalizedClientName,
|
|
2607
|
+
matchCount: uniqueMatches.size,
|
|
2608
|
+
matchedClientId: matchedClientId || undefined
|
|
2609
|
+
};
|
|
2610
|
+
};
|
|
2611
|
+
|
|
2612
|
+
node.fetchPresenceObservationSnapshotForDescriptor = async (descriptor, activeClients) => {
|
|
2613
|
+
const matchBy = normalizePresenceMatchBy(descriptor && descriptor.matchBy);
|
|
2614
|
+
if (matchBy === "name") {
|
|
2615
|
+
return node.fetchPresenceObservationSnapshotByName(
|
|
2616
|
+
descriptor && descriptor.clientId,
|
|
2617
|
+
descriptor && descriptor.clientName,
|
|
2618
|
+
descriptor && descriptor.timeout,
|
|
2619
|
+
activeClients
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
2622
|
+
return node.fetchPresenceObservationSnapshot(
|
|
2623
|
+
descriptor && descriptor.clientId,
|
|
2624
|
+
descriptor && descriptor.timeout
|
|
2625
|
+
);
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2506
2628
|
node.requestPresenceObservationNow = async (descriptor) => {
|
|
2507
2629
|
if (!descriptor || typeof descriptor !== "object") {
|
|
2508
2630
|
throw new Error("Invalid presence descriptor.");
|
|
2509
2631
|
}
|
|
2510
|
-
const snapshot = await node.
|
|
2632
|
+
const snapshot = await node.fetchPresenceObservationSnapshotForDescriptor(descriptor);
|
|
2511
2633
|
return {
|
|
2512
2634
|
source: normalizeString(descriptor.source) || "manual-input",
|
|
2513
2635
|
...snapshot,
|
|
@@ -2542,9 +2664,14 @@ module.exports = function(RED) {
|
|
|
2542
2664
|
}
|
|
2543
2665
|
|
|
2544
2666
|
const clientId = normalizeString(descriptor.clientId);
|
|
2667
|
+
const matchBy = normalizePresenceMatchBy(descriptor.matchBy);
|
|
2668
|
+
const clientName = normalizeString(descriptor.clientName);
|
|
2545
2669
|
const pollIntervalSeconds = Number(descriptor.pollIntervalSeconds);
|
|
2546
2670
|
const timeout = Number(descriptor.timeout);
|
|
2547
|
-
if (!clientId
|
|
2671
|
+
if (!clientId
|
|
2672
|
+
|| (matchBy === "name" && !clientName)
|
|
2673
|
+
|| !Number.isFinite(pollIntervalSeconds)
|
|
2674
|
+
|| pollIntervalSeconds <= 0) {
|
|
2548
2675
|
return null;
|
|
2549
2676
|
}
|
|
2550
2677
|
|
|
@@ -2552,6 +2679,8 @@ module.exports = function(RED) {
|
|
|
2552
2679
|
client,
|
|
2553
2680
|
descriptor: {
|
|
2554
2681
|
clientId,
|
|
2682
|
+
matchBy,
|
|
2683
|
+
clientName,
|
|
2555
2684
|
pollIntervalMs: Math.max(1000, Math.trunc(pollIntervalSeconds * 1000)),
|
|
2556
2685
|
timeout: Number.isFinite(timeout) && timeout > 0 ? Math.trunc(timeout) : 8000
|
|
2557
2686
|
}
|
|
@@ -2634,9 +2763,14 @@ module.exports = function(RED) {
|
|
|
2634
2763
|
}
|
|
2635
2764
|
|
|
2636
2765
|
state.nextRunAt = now + entry.descriptor.pollIntervalMs;
|
|
2637
|
-
const
|
|
2766
|
+
const scoped = resolveScopedIdentifiers("client", entry.descriptor.clientId);
|
|
2767
|
+
const key = entry.descriptor.matchBy === "name"
|
|
2768
|
+
? `name::${scoped.siteId}::${normalizeClientMatchName(entry.descriptor.clientName)}`
|
|
2769
|
+
: `id::${entry.descriptor.clientId}`;
|
|
2638
2770
|
const group = dueGroups.get(key) || {
|
|
2639
2771
|
clientId: entry.descriptor.clientId,
|
|
2772
|
+
matchBy: entry.descriptor.matchBy,
|
|
2773
|
+
clientName: entry.descriptor.clientName,
|
|
2640
2774
|
timeout: entry.descriptor.timeout,
|
|
2641
2775
|
entries: []
|
|
2642
2776
|
};
|
|
@@ -2645,10 +2779,22 @@ module.exports = function(RED) {
|
|
|
2645
2779
|
dueGroups.set(key, group);
|
|
2646
2780
|
});
|
|
2647
2781
|
|
|
2782
|
+
const activeClientsBySite = new Map();
|
|
2648
2783
|
for (const group of dueGroups.values()) {
|
|
2649
2784
|
let snapshot;
|
|
2650
2785
|
try {
|
|
2651
|
-
|
|
2786
|
+
let activeClients;
|
|
2787
|
+
if (group.matchBy === "name") {
|
|
2788
|
+
const scoped = resolveScopedIdentifiers("client", group.clientId);
|
|
2789
|
+
if (!activeClientsBySite.has(scoped.siteId)) {
|
|
2790
|
+
activeClientsBySite.set(
|
|
2791
|
+
scoped.siteId,
|
|
2792
|
+
node.fetchActivePresenceClients(scoped.siteId, group.timeout)
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
activeClients = await activeClientsBySite.get(scoped.siteId);
|
|
2796
|
+
}
|
|
2797
|
+
snapshot = await node.fetchPresenceObservationSnapshotForDescriptor(group, activeClients);
|
|
2652
2798
|
} catch (error) {
|
|
2653
2799
|
snapshot = {
|
|
2654
2800
|
found: false,
|
|
@@ -2663,6 +2809,8 @@ module.exports = function(RED) {
|
|
|
2663
2809
|
node.notifyPresenceObserverClient(entry.client, {
|
|
2664
2810
|
source: "poll",
|
|
2665
2811
|
clientId: group.clientId,
|
|
2812
|
+
matchBy: group.matchBy,
|
|
2813
|
+
clientName: group.clientName,
|
|
2666
2814
|
...snapshot
|
|
2667
2815
|
});
|
|
2668
2816
|
});
|
|
@@ -941,7 +941,20 @@
|
|
|
941
941
|
$deviceId.append($option);
|
|
942
942
|
});
|
|
943
943
|
|
|
944
|
-
|
|
944
|
+
const hasCurrentValue = currentValue && $deviceId.find("option").filter(function () {
|
|
945
|
+
return String($(this).val() || "") === currentValue;
|
|
946
|
+
}).length > 0;
|
|
947
|
+
if (hasCurrentValue) {
|
|
948
|
+
$deviceId.val(currentValue);
|
|
949
|
+
} else if (currentValue) {
|
|
950
|
+
const savedName = String(node.deviceName || currentValue).trim();
|
|
951
|
+
$deviceId.append(
|
|
952
|
+
$("<option></option>")
|
|
953
|
+
.val(currentValue)
|
|
954
|
+
.text(savedName + " (saved; currently unavailable)")
|
|
955
|
+
.attr("data-device-name", savedName)
|
|
956
|
+
.attr("data-unavailable", "true")
|
|
957
|
+
);
|
|
945
958
|
$deviceId.val(currentValue);
|
|
946
959
|
} else {
|
|
947
960
|
$deviceId.val("");
|
|
@@ -955,16 +968,28 @@
|
|
|
955
968
|
}
|
|
956
969
|
|
|
957
970
|
function renderDevicesLoading(label) {
|
|
971
|
+
const savedValue = getCurrentOrNodeValue($deviceId, node.deviceId, "");
|
|
972
|
+
const savedName = String(node.deviceName || savedValue).trim();
|
|
958
973
|
clientTargetsLoading = isClientResourceSelected();
|
|
959
974
|
clientTargetsPopulated = false;
|
|
960
975
|
withSuppressedChanges(function () {
|
|
961
976
|
$deviceId.empty();
|
|
962
|
-
|
|
963
|
-
$(
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
977
|
+
if (savedValue) {
|
|
978
|
+
$deviceId.append(
|
|
979
|
+
$("<option></option>")
|
|
980
|
+
.val(savedValue)
|
|
981
|
+
.text(savedName + " (loading...)")
|
|
982
|
+
.attr("data-device-name", savedName)
|
|
983
|
+
);
|
|
984
|
+
$deviceId.val(savedValue);
|
|
985
|
+
} else {
|
|
986
|
+
$deviceId.append(
|
|
987
|
+
$("<option></option>")
|
|
988
|
+
.val("")
|
|
989
|
+
.text(label)
|
|
990
|
+
);
|
|
991
|
+
$deviceId.val("");
|
|
992
|
+
}
|
|
968
993
|
});
|
|
969
994
|
|
|
970
995
|
makeSelectSearchable($deviceId, label);
|
|
@@ -1197,6 +1222,7 @@
|
|
|
1197
1222
|
});
|
|
1198
1223
|
|
|
1199
1224
|
refreshSelectionSummary();
|
|
1225
|
+
renderDevicesLoading("Loading items, please wait...");
|
|
1200
1226
|
ensureDefaultServerSelection();
|
|
1201
1227
|
$refresh.find("i").addClass("fa-spin");
|
|
1202
1228
|
refreshEditor();
|
|
@@ -1265,7 +1291,7 @@
|
|
|
1265
1291
|
<h3>Configuration</h3>
|
|
1266
1292
|
<p><b>Connection</b> selects the shared UniFi Network config node.</p>
|
|
1267
1293
|
<p><b>Resource</b> chooses what you want to work with: Site, UniFi Device, or Client.</p>
|
|
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>
|
|
1294
|
+
<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. A saved selection that is offline or temporarily unavailable is preserved instead of being cleared.</p>
|
|
1269
1295
|
<p><b>Action</b> only shows actions supported by the selected resource. Additional fields appear only when the selected action needs extra input.</p>
|
|
1270
1296
|
<p>Action highlights include <code>Count Online Clients</code>, <code>List Networks</code>, <code>List Wi-Fi Broadcasts</code>, <code>List WAN Interfaces</code>, <code>List VPN Servers</code>, <code>List Site-to-Site VPN Tunnels</code>, <code>List Guest Vouchers</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>
|
|
1271
1297
|
<p><code>Read Application Info</code> is available on the <code>Site</code> resource type and returns Network application metadata.</p>
|