node-red-contrib-unifi-ultimate 1.1.17 → 1.1.18
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 +1 -0
- package/examples/unifi-protect-alarm-state.json +84 -0
- package/nodes/unifi-network-device.html +2 -1
- package/nodes/unifi-protect-config.js +2 -1
- package/nodes/unifi-protect-device.html +8 -2
- package/nodes/unifi-protect-device.js +38 -8
- package/nodes/utils/unifi-protect-alarm.js +59 -0
- package/nodes/utils/unifi-protect-device-registry.js +10 -1
- package/nodes/utils/unifi-protect-field-metadata.js +12 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -149,6 +149,7 @@ Things you can do:
|
|
|
149
149
|
- Monitor bridges, Link Stations, alarm hubs, key fobs, sirens, relays, and speakers.
|
|
150
150
|
- Play or stop a siren, control relay outputs, and test speaker or siren sound.
|
|
151
151
|
- Read and select Protect Arm Profiles, then arm or disarm the local Alarm Manager from the NVR control.
|
|
152
|
+
- Poll Alarm Hub armed state or NVR local alarm status with **Read Alarm State**, or follow device updates with **Receive Events → Armed / Alarm status (local)**. These are separate alarm sources; the NVR arm commands require the local Alarm Manager. See [the polling example](examples/unifi-protect-alarm-state.json).
|
|
152
153
|
|
|
153
154
|
### Read license plates (LPR)
|
|
154
155
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "flow-protect-alarm-poll",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "Protect Alarm State",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Select your Protect connection and Alarm Hub in Read Alarm State. Polls every 60 seconds and after deployment. Hub payload is boolean; NVR payload is the local armMode.status string. Requires a version with Read Alarm State support."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "inject-protect-alarm-poll",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"z": "flow-protect-alarm-poll",
|
|
13
|
+
"name": "Poll every 60 seconds",
|
|
14
|
+
"props": [],
|
|
15
|
+
"repeat": "60",
|
|
16
|
+
"crontab": "",
|
|
17
|
+
"once": true,
|
|
18
|
+
"onceDelay": 5,
|
|
19
|
+
"topic": "",
|
|
20
|
+
"x": 170,
|
|
21
|
+
"y": 120,
|
|
22
|
+
"wires": [
|
|
23
|
+
[
|
|
24
|
+
"read-protect-alarm-state"
|
|
25
|
+
]
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "read-protect-alarm-state",
|
|
30
|
+
"type": "unifi-protect-device",
|
|
31
|
+
"z": "flow-protect-alarm-poll",
|
|
32
|
+
"name": "Read Alarm State (Hub)",
|
|
33
|
+
"server": "",
|
|
34
|
+
"deviceType": "alarmHub",
|
|
35
|
+
"deviceId": "",
|
|
36
|
+
"deviceName": "",
|
|
37
|
+
"inputs": 1,
|
|
38
|
+
"capability": "getAlarmState",
|
|
39
|
+
"capabilityConfig": "{}",
|
|
40
|
+
"emitStartupAndUndefined": false,
|
|
41
|
+
"autoEmit": false,
|
|
42
|
+
"autoEmitInterval": 60,
|
|
43
|
+
"x": 440,
|
|
44
|
+
"y": 120,
|
|
45
|
+
"wires": [
|
|
46
|
+
[
|
|
47
|
+
"debug-protect-alarm-status"
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"debug-protect-alarm-error"
|
|
51
|
+
]
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "debug-protect-alarm-status",
|
|
56
|
+
"type": "debug",
|
|
57
|
+
"z": "flow-protect-alarm-poll",
|
|
58
|
+
"name": "Current alarm status",
|
|
59
|
+
"active": true,
|
|
60
|
+
"tosidebar": true,
|
|
61
|
+
"console": false,
|
|
62
|
+
"tostatus": false,
|
|
63
|
+
"complete": "payload",
|
|
64
|
+
"targetType": "msg",
|
|
65
|
+
"x": 990,
|
|
66
|
+
"y": 100,
|
|
67
|
+
"wires": []
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "debug-protect-alarm-error",
|
|
71
|
+
"type": "debug",
|
|
72
|
+
"z": "flow-protect-alarm-poll",
|
|
73
|
+
"name": "Error / missing alarm state",
|
|
74
|
+
"active": true,
|
|
75
|
+
"tosidebar": true,
|
|
76
|
+
"console": false,
|
|
77
|
+
"tostatus": false,
|
|
78
|
+
"complete": "true",
|
|
79
|
+
"targetType": "full",
|
|
80
|
+
"x": 730,
|
|
81
|
+
"y": 200,
|
|
82
|
+
"wires": []
|
|
83
|
+
}
|
|
84
|
+
]
|
|
@@ -1237,6 +1237,7 @@
|
|
|
1237
1237
|
refreshEditor();
|
|
1238
1238
|
}
|
|
1239
1239
|
});
|
|
1240
|
+
|
|
1240
1241
|
</script>
|
|
1241
1242
|
|
|
1242
1243
|
<script type="text/html" data-template-name="unifi-network-device">
|
|
@@ -1401,4 +1402,4 @@ msg.payload = { state: "failover", interface: "eth9", at: "2026-09-12T12:00:00.0
|
|
|
1401
1402
|
"payload": null,
|
|
1402
1403
|
"error": { "message": "Request timed out" }
|
|
1403
1404
|
}</code></pre>
|
|
1404
|
-
</script>
|
|
1405
|
+
</script>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { registerConnectionCheck } = require("./utils/unifi-connection-check");
|
|
4
4
|
const { actionGuidance } = require("./utils/unifi-action-guidance");
|
|
5
|
+
const { buildRequestError } = require("./utils/unifi-protect-alarm");
|
|
5
6
|
|
|
6
7
|
const {
|
|
7
8
|
buildBaseUrlFromHost,
|
|
@@ -411,7 +412,7 @@ module.exports = function(RED) {
|
|
|
411
412
|
method: "GET"
|
|
412
413
|
});
|
|
413
414
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
414
|
-
throw
|
|
415
|
+
throw buildRequestError(response, "GET", path, [...Object.values(node.credentials || {}), node.getApiKey()]);
|
|
415
416
|
}
|
|
416
417
|
return response.payload;
|
|
417
418
|
};
|
|
@@ -1190,6 +1190,9 @@
|
|
|
1190
1190
|
<span style="margin-left:8px;">seconds</span>
|
|
1191
1191
|
</div>
|
|
1192
1192
|
</div>
|
|
1193
|
+
<br/>
|
|
1194
|
+
<br/>
|
|
1195
|
+
<br/>
|
|
1193
1196
|
</script>
|
|
1194
1197
|
|
|
1195
1198
|
<script type="text/html" data-help-name="unifi-protect-device">
|
|
@@ -1206,7 +1209,10 @@
|
|
|
1206
1209
|
<p>Action highlights: <code>Receive Events</code>, <code>Read Device State</code>, <code>Take Snapshot</code>, <code>Show Doorbell Message</code>, siren play/stop/test, relay output control, speaker sound test, and application/alarm actions on <code>NVR</code>.</p>
|
|
1207
1210
|
<p>Protect resources include cameras, sensors, lights, chimes, viewers, live views, NVRs, bridges, Link Stations, alarm hubs, key fobs, relays, sirens, and speakers. The newer device families expose read state and events without the generic raw-update action.</p>
|
|
1208
1211
|
<p><code>Play Siren</code> uses a duration in seconds. <code>Control Relay Output</code> requires an explicit output and on/off state; auto-off applies only when turning an output on. <code>Trigger Alarm Hub Output</code> can toggle an output or set it on/off, with an optional delay and duration. Sound-test actions use a configured volume and never read control values from the incoming message.</p>
|
|
1209
|
-
<p>
|
|
1212
|
+
<p>The <code>NVR</code> arm profile commands control Protect's local Alarm Manager; they do not necessarily control the alarm managed by an Alarm Hub or a global Alarm Manager. Use <code>Read Arm Profiles</code>, <code>Select Arm Profile</code>, <code>Arm Alarm</code>, and <code>Disarm Alarm</code>. These endpoints require Protect's local Alarm Manager.</p>
|
|
1213
|
+
<p><code>Read Alarm State</code> is available on <code>Alarm Hub</code> and <code>NVR</code>. On an Alarm Hub it reads <code>alarmHub.armed</code> and emits <code>true</code> for <code>on</code> or <code>false</code> for <code>off</code>. On an NVR it emits the local Alarm Manager's <code>armMode.status</code> string without converting transitional or unknown statuses to a boolean. The full device remains in <code>msg.details.device</code>. Missing or unsupported state goes to output 2; it never means disarmed. Trigger this action with an Inject node or enable periodic reads for recovery after missed updates or controller restarts.</p>
|
|
1214
|
+
<p>For live state, choose <code>Receive Events → Armed</code> on an Alarm Hub, or <code>Receive Events → Alarm status (local)</code> on an NVR. These values follow device updates, rather than assuming a dedicated arm/disarm event exists. Enable startup emission if you need an initial value after deploy. Delivery depends on Protect publishing device updates; use periodic <code>Read Alarm State</code> for recovery. NVR state and Hub state are separate sources and can differ.</p>
|
|
1215
|
+
<p>Arm/Disarm commands use the configured Protect API key and its account permissions. The optional local username/password used for recorded events does not grant permissions to these commands. HTTP 401 suggests checking the key; 403 suggests checking permissions. HTTP 400 alone does not establish a permission problem: check the selected profile and whether the local Alarm Manager is in use. Request failures include HTTP status, method, path and a bounded, redacted API message when available in <code>msg.details.response</code>. No automatic fallback to raw updates, relay outputs or undocumented alarm controls is performed.</p>
|
|
1210
1216
|
<p><code>Receive Events</code> performs an initial fetch and then subscribes to streams managed by the shared Protect config node. The config node keeps websocket channels and forwards matching updates to runtime nodes. In this mode, the input pin is hidden and listening starts automatically after deploy/restart.</p>
|
|
1211
1217
|
<p>For <code>Sensor</code>, <code>Camera</code>, <code>Light</code>, <code>Key Fob</code>, <code>Relay</code>, and <code>Alarm Hub</code> observables, <code>All</code> emits every event for the selected device. Choosing a specific observable normalizes the main output to a derived value and keeps the original context in <code>msg.details.raw</code>. Event observables emit <code>true/false</code>; sensor metrics such as <code>Temperature</code>, <code>Humidity</code>, <code>Light Level</code>, and <code>Battery Level</code> emit numeric values. <code>License Plate (LPR)</code> emits recognized plate text.</p>
|
|
1212
1218
|
<p>For <code>Key Fob</code>, the event list includes <code>Arm (1)</code>, <code>Night (2)</code>, <code>Disarm (3)</code>, <code>Panic (4)</code>, <code>Left</code>, and <code>Right</code>. The two side buttons have no printed number. Selecting one emits <code>true</code> only for that button; the original <code>sensorButtonPressed</code> event remains available in <code>msg.details.raw</code>.</p>
|
|
@@ -1312,4 +1318,4 @@ XY456ZT = Delivery van</code></pre>
|
|
|
1312
1318
|
"payload": null,
|
|
1313
1319
|
"error": { "message": "Request timed out" }
|
|
1314
1320
|
}</code></pre>
|
|
1315
|
-
</script>
|
|
1321
|
+
</script>
|
|
@@ -24,6 +24,7 @@ const {
|
|
|
24
24
|
} = require("./utils/common-utils");
|
|
25
25
|
const { parseKnownPlates, namePlate, matchesDetection, describeDetection } = require("./utils/unifi-protect-detections");
|
|
26
26
|
const { LICENSE_PLATE_EVENT_TYPES, extractLicensePlates, isLicensePlateEvent } = require("./utils/unifi-protect-lpr");
|
|
27
|
+
const { readAlarmState, matchesDeviceUpdate, mergeDeviceUpdate, buildRequestError } = require("./utils/unifi-protect-alarm");
|
|
27
28
|
const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
|
|
28
29
|
const LPR_FOLLOW_UP_DELAYS_MS = [150, 350, 750, 1500, 3000];
|
|
29
30
|
|
|
@@ -143,6 +144,12 @@ module.exports = function(RED) {
|
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
function protectErrorOutput(error) {
|
|
148
|
+
const message = buildErrorOutputMessage(error, node.name);
|
|
149
|
+
if (error.protectResponse) attachDetails(message, { response: error.protectResponse });
|
|
150
|
+
return message;
|
|
151
|
+
}
|
|
152
|
+
|
|
146
153
|
function resolveOutputDeviceName(payload) {
|
|
147
154
|
const extracted = extractDeviceNameFromPayload(payload);
|
|
148
155
|
if (extracted) {
|
|
@@ -324,7 +331,9 @@ module.exports = function(RED) {
|
|
|
324
331
|
|
|
325
332
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
326
333
|
setNodeStatus({ fill: "yellow", shape: "ring", text: `${response.statusCode}` });
|
|
327
|
-
|
|
334
|
+
const secrets = Object.values(node.server.credentials || {});
|
|
335
|
+
if (typeof node.server.getApiKey === "function") secrets.push(node.server.getApiKey());
|
|
336
|
+
throw buildRequestError(response, request.method, request.path, secrets);
|
|
328
337
|
}
|
|
329
338
|
|
|
330
339
|
if (response.payload && typeof response.payload === "object" && !Array.isArray(response.payload)) {
|
|
@@ -335,6 +344,13 @@ module.exports = function(RED) {
|
|
|
335
344
|
payload: response.payload
|
|
336
345
|
};
|
|
337
346
|
decorateOutputMessage(stateMsg, response.payload, `request:${capabilityId}`);
|
|
347
|
+
if (capabilityId === "getAlarmState") {
|
|
348
|
+
const alarmState = readAlarmState(deviceType, response.payload);
|
|
349
|
+
if (alarmState === undefined) {
|
|
350
|
+
throw new Error(`The ${deviceType} response has no supported alarm state. Check the Protect version and alarm mode; missing state does not mean disarmed.`);
|
|
351
|
+
}
|
|
352
|
+
stateMsg.payload = alarmState;
|
|
353
|
+
}
|
|
338
354
|
attachDetails(stateMsg, {
|
|
339
355
|
response: {
|
|
340
356
|
statusCode: response.statusCode,
|
|
@@ -410,9 +426,10 @@ module.exports = function(RED) {
|
|
|
410
426
|
}
|
|
411
427
|
|
|
412
428
|
fetchDeviceState(node.deviceType, node.deviceId, parseCapabilityConfig(node.capabilityConfig), node.send.bind(node), "startup").catch((error) => {
|
|
413
|
-
if (node.isObserving && (isPhotoObservation() || isLicensePlateObservation())) {
|
|
429
|
+
if (node.isObserving && (isPhotoObservation() || isLicensePlateObservation() || node.deviceType === "alarmHub" || node.deviceType === "nvr")) {
|
|
414
430
|
setNodeStatus({ fill: "red", shape: "ring", text: "check camera configuration" });
|
|
415
|
-
node.
|
|
431
|
+
if (node.deviceType === "alarmHub" || node.deviceType === "nvr") setNodeStatus({ fill: "red", shape: "ring", text: "alarm state unavailable" });
|
|
432
|
+
node.send([null, protectErrorOutput(error)]);
|
|
416
433
|
}
|
|
417
434
|
});
|
|
418
435
|
}
|
|
@@ -444,7 +461,7 @@ module.exports = function(RED) {
|
|
|
444
461
|
invokeCapability(node.send.bind(node), "interval")
|
|
445
462
|
.catch((error) => {
|
|
446
463
|
setNodeStatus({ fill: "red", shape: "ring", text: "auto error" });
|
|
447
|
-
node.send([null,
|
|
464
|
+
node.send([null, protectErrorOutput(error)]);
|
|
448
465
|
node.error(error);
|
|
449
466
|
})
|
|
450
467
|
.finally(() => {
|
|
@@ -474,7 +491,7 @@ module.exports = function(RED) {
|
|
|
474
491
|
}
|
|
475
492
|
} catch (error) {
|
|
476
493
|
setNodeStatus({ fill: "red", shape: "ring", text: "error" });
|
|
477
|
-
node.send([null,
|
|
494
|
+
node.send([null, protectErrorOutput(error)]);
|
|
478
495
|
if (typeof done === "function") {
|
|
479
496
|
done(error);
|
|
480
497
|
} else {
|
|
@@ -493,19 +510,32 @@ module.exports = function(RED) {
|
|
|
493
510
|
// Only react to device updates that match both the selected
|
|
494
511
|
// model family and the exact configured device id.
|
|
495
512
|
const deviceDefinition = getDeviceTypeDefinition(node.deviceType);
|
|
496
|
-
|
|
513
|
+
const alarmDevice = node.deviceType === "alarmHub" || node.deviceType === "nvr";
|
|
514
|
+
if (!deviceDefinition || (alarmDevice
|
|
515
|
+
? !matchesDeviceUpdate(node.deviceType, node.deviceId, item, deviceDefinition.modelKey)
|
|
516
|
+
: item.modelKey !== deviceDefinition.modelKey || item.id !== node.deviceId)) {
|
|
497
517
|
return;
|
|
498
518
|
}
|
|
499
519
|
|
|
500
|
-
|
|
520
|
+
if (alarmDevice && ["remove", "delete"].includes(update.type)) {
|
|
521
|
+
node.currentDevice = null;
|
|
522
|
+
node.currentObservableValue = undefined;
|
|
523
|
+
setNodeStatus({ fill: "yellow", shape: "ring", text: "device removed" });
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
node.currentDevice = alarmDevice ? mergeDeviceUpdate(node.currentDevice, item) : item;
|
|
501
527
|
if (isLicensePlateObservation() || isPhotoObservation()) return;
|
|
502
528
|
const capabilityConfig = parseCapabilityConfig(node.capabilityConfig);
|
|
529
|
+
const observable = resolveConfiguredObservable(capabilityConfig);
|
|
530
|
+
// An unrelated partial update must not replay an old alarm value.
|
|
531
|
+
if ((node.deviceType === "alarmHub" && observable === "armed" && !(item.alarmHub && Object.prototype.hasOwnProperty.call(item.alarmHub, "armed")))
|
|
532
|
+
|| (node.deviceType === "nvr" && observable === "armStatus" && !(item.armMode && Object.prototype.hasOwnProperty.call(item.armMode, "status")))) return;
|
|
503
533
|
setNodeStatus({ fill: "green", shape: "dot", text: buildNodeStatus(node.deviceType, item) });
|
|
504
534
|
sendOutputs(node.send.bind(node), buildObservedStateMessage(
|
|
505
535
|
node.deviceType,
|
|
506
536
|
node.deviceId,
|
|
507
537
|
capabilityConfig,
|
|
508
|
-
|
|
538
|
+
node.currentDevice,
|
|
509
539
|
"devices",
|
|
510
540
|
{ updateType: update.type || "" },
|
|
511
541
|
update.type || "devices"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function readAlarmState(deviceType, device) {
|
|
4
|
+
if (deviceType === "alarmHub") {
|
|
5
|
+
const value = device && device.alarmHub && device.alarmHub.armed;
|
|
6
|
+
if (value === true || value === "on") return true;
|
|
7
|
+
if (value === false || value === "off") return false;
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const status = device && device.armMode && device.armMode.status;
|
|
11
|
+
return deviceType === "nvr" && typeof status === "string" && status.trim()
|
|
12
|
+
? status : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function matchesDeviceUpdate(deviceType, deviceId, item, modelKey) {
|
|
16
|
+
if (!item || item.id !== deviceId) return false;
|
|
17
|
+
// Partial updates may omit the model key. IDs still scope them to the
|
|
18
|
+
// configured device. Protect also represents Alarm Hubs as Link Stations.
|
|
19
|
+
return !item.modelKey || item.modelKey === modelKey
|
|
20
|
+
|| (deviceType === "alarmHub" && item.modelKey === "linkStation")
|
|
21
|
+
|| (deviceType === "alarmHub" && item.modelKey === "linkstation");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function mergeDeviceUpdate(previous, update) {
|
|
25
|
+
const result = { ...(previous || {}) };
|
|
26
|
+
for (const [key, value] of Object.entries(update)) {
|
|
27
|
+
if (["__proto__", "constructor", "prototype"].includes(key)) continue;
|
|
28
|
+
result[key] = value && typeof value === "object" && !Array.isArray(value)
|
|
29
|
+
? mergeDeviceUpdate(result[key] && typeof result[key] === "object" ? result[key] : null, value)
|
|
30
|
+
: value;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function buildRequestError(response, method, path, secrets) {
|
|
36
|
+
const statusCode = Number(response.statusCode);
|
|
37
|
+
const body = response.payload;
|
|
38
|
+
const detail = body && typeof body === "object"
|
|
39
|
+
? (body.message || (body.error && body.error.message) || (typeof body.error === "string" ? body.error : ""))
|
|
40
|
+
: typeof body === "string" ? body : "";
|
|
41
|
+
let apiMessage = typeof detail === "string" ? detail : "";
|
|
42
|
+
for (const secret of secrets || []) {
|
|
43
|
+
if (typeof secret === "string" && secret) apiMessage = apiMessage.split(secret).join("[redacted]");
|
|
44
|
+
}
|
|
45
|
+
apiMessage = apiMessage.replace(/(bearer\s+)\S+/gi, "$1[redacted]")
|
|
46
|
+
.replace(/((?:password|token|api[-_ ]?key|authorization|cookie)\s*[=:]\s*)[^\s,;]+/gi, "$1[redacted]")
|
|
47
|
+
.replace(/[\r\n\t]+/g, " ").slice(0, 500);
|
|
48
|
+
let hint = "";
|
|
49
|
+
if (statusCode === 401) hint = " Check the Protect API key and its validity.";
|
|
50
|
+
if (statusCode === 403) hint = " Check the Protect permissions of the account associated with the API key.";
|
|
51
|
+
if (statusCode === 400 && path.startsWith("/v1/arm-profiles")) {
|
|
52
|
+
hint = " Arm profile commands require Protect's local Alarm Manager; check the alarm mode and selected profile. A 400 response alone does not identify a permission failure.";
|
|
53
|
+
}
|
|
54
|
+
const error = new Error(`UniFi Protect request failed with status ${statusCode}.${hint}${apiMessage ? ` API: ${apiMessage}` : ""}`);
|
|
55
|
+
error.protectResponse = { statusCode, method, path, ...(apiMessage ? { apiMessage } : {}) };
|
|
56
|
+
return error;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = { readAlarmState, matchesDeviceUpdate, mergeDeviceUpdate, buildRequestError };
|
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
} = require("./unifi-protect-field-metadata");
|
|
10
10
|
const { DETECTION_FIELD, KNOWN_PLATES_FIELD } = require("./unifi-protect-detections");
|
|
11
11
|
const { LICENSE_PLATE_EVENT_TYPES, extractLicensePlates } = require("./unifi-protect-lpr");
|
|
12
|
+
const { readAlarmState } = require("./unifi-protect-alarm");
|
|
12
13
|
|
|
13
14
|
// Central Protect registry used by:
|
|
14
15
|
// - the editor for device/capability discovery
|
|
@@ -360,6 +361,7 @@ const RELAY_OBSERVABLE_DEFINITIONS = [
|
|
|
360
361
|
];
|
|
361
362
|
|
|
362
363
|
const ALARM_HUB_OBSERVABLE_DEFINITIONS = [
|
|
364
|
+
{ id: "armed", label: "Armed", eventTypes: [] },
|
|
363
365
|
{
|
|
364
366
|
id: "motion",
|
|
365
367
|
label: "Motion input",
|
|
@@ -724,6 +726,7 @@ const TYPE_CAPABILITIES = {
|
|
|
724
726
|
createSetPropertyCapability()
|
|
725
727
|
],
|
|
726
728
|
nvr: [
|
|
729
|
+
{ id: "getAlarmState", label: "Read Alarm State", description: "Read the local Alarm Manager status from the NVR.", method: "GET", pathKind: "detail", mode: "request" },
|
|
727
730
|
{
|
|
728
731
|
id: "getApplicationInfo",
|
|
729
732
|
label: "Read Application Info",
|
|
@@ -792,6 +795,7 @@ const TYPE_CAPABILITIES = {
|
|
|
792
795
|
bridge: [],
|
|
793
796
|
linkStation: [],
|
|
794
797
|
alarmHub: [
|
|
798
|
+
{ id: "getAlarmState", label: "Read Alarm State", description: "Read the selected Alarm Hub's armed state.", method: "GET", pathKind: "detail", mode: "request" },
|
|
795
799
|
{
|
|
796
800
|
id: "triggerAlarmHubOutput",
|
|
797
801
|
label: "Trigger Alarm Hub Output",
|
|
@@ -1923,7 +1927,8 @@ function getObservableDefinitions(deviceType) {
|
|
|
1923
1927
|
light: LIGHT_OBSERVABLE_DEFINITIONS,
|
|
1924
1928
|
fob: FOB_OBSERVABLE_DEFINITIONS,
|
|
1925
1929
|
relay: RELAY_OBSERVABLE_DEFINITIONS,
|
|
1926
|
-
alarmHub: ALARM_HUB_OBSERVABLE_DEFINITIONS
|
|
1930
|
+
alarmHub: ALARM_HUB_OBSERVABLE_DEFINITIONS,
|
|
1931
|
+
nvr: [{ id: "armStatus", label: "Alarm status (local)", eventTypes: [] }]
|
|
1927
1932
|
};
|
|
1928
1933
|
|
|
1929
1934
|
return definitionsByDeviceType[String(deviceType || "").trim()] || [];
|
|
@@ -1952,6 +1957,10 @@ function resolveSelectedObservable(options, configuredObservable) {
|
|
|
1952
1957
|
}
|
|
1953
1958
|
|
|
1954
1959
|
function resolveObservableState(deviceType, device, observable, fallbackValue) {
|
|
1960
|
+
if ((deviceType === "alarmHub" && observable === "armed") || (deviceType === "nvr" && observable === "armStatus")) {
|
|
1961
|
+
const value = readAlarmState(deviceType, device);
|
|
1962
|
+
return value === undefined ? fallbackValue : value;
|
|
1963
|
+
}
|
|
1955
1964
|
if (deviceType === "sensor") {
|
|
1956
1965
|
return resolveSensorObservableState(device, observable, fallbackValue);
|
|
1957
1966
|
}
|
|
@@ -28,6 +28,13 @@ const COMMON_FIELD_METADATA = {
|
|
|
28
28
|
|
|
29
29
|
// Device-family-specific metadata overrides or extends the common dictionary.
|
|
30
30
|
const TYPE_FIELD_METADATA = {
|
|
31
|
+
nvr: {
|
|
32
|
+
armStatus: {
|
|
33
|
+
label: "Alarm Status (Local)",
|
|
34
|
+
description: "Local Alarm Manager status from armMode.status. Kept as a string, including transitional states; it may differ from an Alarm Hub's armed state.",
|
|
35
|
+
source: "official"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
31
38
|
camera: {
|
|
32
39
|
isMicEnabled: {
|
|
33
40
|
label: "Microphone Enabled",
|
|
@@ -366,6 +373,11 @@ const OBSERVABLE_METADATA = {
|
|
|
366
373
|
}
|
|
367
374
|
},
|
|
368
375
|
alarmHub: {
|
|
376
|
+
armed: {
|
|
377
|
+
label: "Armed",
|
|
378
|
+
description: "Current Alarm Hub armed state: on becomes true and off becomes false. Updated by device state messages, not a dedicated arm/disarm event.",
|
|
379
|
+
source: "official"
|
|
380
|
+
},
|
|
369
381
|
motion: {
|
|
370
382
|
label: "Motion Input",
|
|
371
383
|
description: "True while an Alarm Hub motion input is active.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-unifi-ultimate",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"description": "Node-RED nodes for Ubiquiti UniFi integrations, including UniFi Protect, UniFi Access, and UniFi Network.",
|
|
5
5
|
"files": [
|
|
6
6
|
"nodes/",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
|
-
"test": "node --check nodes/unifi-access-config.js && node --check nodes/unifi-access-device.js && node --check nodes/unifi-network-config.js && node --check nodes/unifi-network-control-poe.js && node --check nodes/unifi-network-device.js && node --check nodes/unifi-network-presence.js && node --check nodes/unifi-network-restart.js && node --check nodes/unifi-protect-config.js && node --check nodes/unifi-protect-device.js && node --check nodes/utils/common-utils.js && node --check nodes/utils/http-response-utils.js && node --check nodes/utils/unifi-access-utils.js && node --check nodes/utils/unifi-access-device-registry.js && node --check nodes/utils/unifi-network-utils.js && node --check nodes/utils/unifi-network-device-registry.js && node --check nodes/utils/unifi-network-presence-utils.js && node --check nodes/utils/unifi-protect-utils.js && node --check nodes/utils/unifi-protect-history.js && node --check nodes/utils/unifi-protect-lpr.js && node --check nodes/utils/unifi-protect-field-metadata.js && node --check nodes/utils/unifi-protect-device-registry.js && node --check nodes/utils/knx-ai-camera-registry.js && node --check scripts/unifi-registry-discovery-common.js && node --check scripts/discover-unifi-network-registry.js && node --check scripts/discover-unifi-protect-registry.js && node --check scripts/discover-unifi-access-registry.js && node --check nodes/utils/unifi-simple-monitor.js && node --check nodes/utils/unifi-network-monitor.js && node --check nodes/utils/unifi-protect-detections.js && node --check nodes/utils/unifi-connection-check.js && node --check nodes/utils/unifi-action-guidance.js && node --check resources/editor/unifi-connection-check.js && jest",
|
|
69
|
+
"test": "node --check nodes/unifi-access-config.js && node --check nodes/unifi-access-device.js && node --check nodes/unifi-network-config.js && node --check nodes/unifi-network-control-poe.js && node --check nodes/unifi-network-device.js && node --check nodes/unifi-network-presence.js && node --check nodes/unifi-network-restart.js && node --check nodes/unifi-protect-config.js && node --check nodes/unifi-protect-device.js && node --check nodes/utils/common-utils.js && node --check nodes/utils/http-response-utils.js && node --check nodes/utils/unifi-access-utils.js && node --check nodes/utils/unifi-access-device-registry.js && node --check nodes/utils/unifi-network-utils.js && node --check nodes/utils/unifi-network-device-registry.js && node --check nodes/utils/unifi-network-presence-utils.js && node --check nodes/utils/unifi-protect-utils.js && node --check nodes/utils/unifi-protect-history.js && node --check nodes/utils/unifi-protect-alarm.js && node --check nodes/utils/unifi-protect-lpr.js && node --check nodes/utils/unifi-protect-field-metadata.js && node --check nodes/utils/unifi-protect-device-registry.js && node --check nodes/utils/knx-ai-camera-registry.js && node --check scripts/unifi-registry-discovery-common.js && node --check scripts/discover-unifi-network-registry.js && node --check scripts/discover-unifi-protect-registry.js && node --check scripts/discover-unifi-access-registry.js && node --check nodes/utils/unifi-simple-monitor.js && node --check nodes/utils/unifi-network-monitor.js && node --check nodes/utils/unifi-protect-detections.js && node --check nodes/utils/unifi-connection-check.js && node --check nodes/utils/unifi-action-guidance.js && node --check resources/editor/unifi-connection-check.js && jest",
|
|
70
70
|
"registry:discover:network": "node scripts/discover-unifi-network-registry.js",
|
|
71
71
|
"registry:discover:protect": "node scripts/discover-unifi-protect-registry.js",
|
|
72
72
|
"registry:discover:access": "node scripts/discover-unifi-access-registry.js"
|