node-red-contrib-unifi-ultimate 1.0.0 → 1.0.1
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 +3 -2
- package/nodes/unifi-access-device.html +1 -1
- package/nodes/unifi-access-device.js +17 -2
- package/nodes/unifi-protect-device.html +1 -1
- package/nodes/unifi-protect-device.js +5 -5
- package/nodes/utils/unifi-access-device-registry.js +142 -5
- 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
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ Common uses:
|
|
|
111
111
|
- Switch viewer live views.
|
|
112
112
|
- Update supported device properties.
|
|
113
113
|
|
|
114
|
-
For supported observables, the node can output
|
|
114
|
+
For supported observables, the node can output normalized values while still keeping the raw UniFi event details available (`true/false` for event states, numeric values for sensor metrics like temperature and humidity).
|
|
115
115
|
|
|
116
116
|
<br/>
|
|
117
117
|
<br/>
|
|
@@ -143,6 +143,7 @@ Common uses:
|
|
|
143
143
|
Most nodes send the result on output 1.
|
|
144
144
|
|
|
145
145
|
Protect and Access device nodes emit both state and live event messages on the same output pin when `Receive Events` is selected.
|
|
146
|
+
On Access nodes, the `Event` selector can filter the stream to official UniFi Access event families, or use `All` for full passthrough.
|
|
146
147
|
|
|
147
148
|
Useful metadata is attached to the output message, for example:
|
|
148
149
|
|
|
@@ -296,7 +297,7 @@ Import from `examples/`:
|
|
|
296
297
|
| Flow file | What it demonstrates |
|
|
297
298
|
| -------------------------------------------------------------------------------------------- | ---------------------------------------------- |
|
|
298
299
|
| [examples/unifi-protect-info.json](examples/unifi-protect-info.json) | Read Protect camera state |
|
|
299
|
-
| [examples/unifi-protect-sensor-observe.json](examples/unifi-protect-sensor-observe.json) | Receive boolean
|
|
300
|
+
| [examples/unifi-protect-sensor-observe.json](examples/unifi-protect-sensor-observe.json) | Receive sensor observables (boolean or numeric) |
|
|
300
301
|
| [examples/unifi-protect-camera-actions.json](examples/unifi-protect-camera-actions.json) | Snapshot, PTZ presets, and doorbell messages |
|
|
301
302
|
| [examples/unifi-access-door-control.json](examples/unifi-access-door-control.json) | Door state, unlock, and temporary lock rule |
|
|
302
303
|
| [examples/unifi-access-intercom-doorbell.json](examples/unifi-access-intercom-doorbell.json) | Intercom observe, trigger, and cancel doorbell |
|
|
@@ -1102,7 +1102,7 @@
|
|
|
1102
1102
|
<p><b>Action</b> only shows actions supported by the selected item.</p>
|
|
1103
1103
|
<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>
|
|
1104
1104
|
<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>
|
|
1105
|
-
<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. The input pin is hidden and listening starts automatically after deploy/restart.</p>
|
|
1105
|
+
<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>
|
|
1106
1106
|
<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>
|
|
1107
1107
|
<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>
|
|
1108
1108
|
<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. <b>Timeout</b> controls the request timeout in milliseconds for API calls.</p>
|
|
@@ -5,7 +5,8 @@ const {
|
|
|
5
5
|
composeCapabilityExecution,
|
|
6
6
|
getCapabilityDefinition,
|
|
7
7
|
getDeviceTypeDefinition,
|
|
8
|
-
matchesEvent
|
|
8
|
+
matchesEvent,
|
|
9
|
+
matchesObservable
|
|
9
10
|
} = require("./utils/unifi-access-device-registry");
|
|
10
11
|
const { extractAccessData } = require("./utils/unifi-access-utils");
|
|
11
12
|
|
|
@@ -127,6 +128,14 @@ function appendStatusTimestamp(text) {
|
|
|
127
128
|
return normalized ? `${normalized} ${suffix}` : suffix;
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
function resolveConfiguredObservable(capabilityConfig) {
|
|
132
|
+
return String(
|
|
133
|
+
capabilityConfig && capabilityConfig.observable !== undefined
|
|
134
|
+
? capabilityConfig.observable
|
|
135
|
+
: "all"
|
|
136
|
+
).trim() || "all";
|
|
137
|
+
}
|
|
138
|
+
|
|
130
139
|
module.exports = function(RED) {
|
|
131
140
|
function UnifiAccessDeviceNode(config) {
|
|
132
141
|
RED.nodes.createNode(this, config);
|
|
@@ -434,6 +443,11 @@ module.exports = function(RED) {
|
|
|
434
443
|
if (!node.isObserving || !matchesEvent(node.deviceType, node.deviceId, node.currentDevice, eventPayload)) {
|
|
435
444
|
return;
|
|
436
445
|
}
|
|
446
|
+
const capabilityConfig = parseCapabilityConfig(node.capabilityConfig);
|
|
447
|
+
const observable = resolveConfiguredObservable(capabilityConfig);
|
|
448
|
+
if (!matchesObservable(eventPayload, observable)) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
437
451
|
const eventName = String(eventPayload.event || "").trim();
|
|
438
452
|
|
|
439
453
|
setNodeStatus({ fill: "blue", shape: "ring", text: eventName || "event" });
|
|
@@ -449,7 +463,8 @@ module.exports = function(RED) {
|
|
|
449
463
|
device: node.currentDevice,
|
|
450
464
|
unifiAccess: buildBaseMetadata(node.deviceType, node.deviceId, "observe", {
|
|
451
465
|
source: "events",
|
|
452
|
-
eventType: eventName
|
|
466
|
+
eventType: eventName,
|
|
467
|
+
observable: observable === "all" ? undefined : observable
|
|
453
468
|
})
|
|
454
469
|
});
|
|
455
470
|
sendOutputs(node.send.bind(node), null, eventMsg);
|
|
@@ -1114,7 +1114,7 @@
|
|
|
1114
1114
|
<p>Additional fields appear only when the selected action needs extra input. For example, events, PTZ presets, live views, or discovered properties.</p>
|
|
1115
1115
|
<p>Action highlights: <code>Receive Events</code>, <code>Read Device State</code>, <code>Take Snapshot</code>, <code>Show Doorbell Message</code>, and <code>Read Application Info</code> on <code>NVR</code>.</p>
|
|
1116
1116
|
<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>
|
|
1117
|
-
<p>For <code>Sensor</code>, <code>Camera</code>, and <code>Light</code> observables, <code>All</code> emits every event for the selected device. Choosing a specific observable normalizes the main output to
|
|
1117
|
+
<p>For <code>Sensor</code>, <code>Camera</code>, and <code>Light</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.</p>
|
|
1118
1118
|
<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. <b>Timeout</b> controls the request timeout in milliseconds for API calls.</p>
|
|
1119
1119
|
|
|
1120
1120
|
<h3>Input</h3>
|
|
@@ -157,7 +157,7 @@ module.exports = function(RED) {
|
|
|
157
157
|
node.deviceName = resolveDeviceName(config.deviceName);
|
|
158
158
|
node.timeout = Number(config.timeout) > 0 ? Number(config.timeout) : 15000;
|
|
159
159
|
node.currentDevice = null;
|
|
160
|
-
node.currentObservableValue =
|
|
160
|
+
node.currentObservableValue = undefined;
|
|
161
161
|
node.isObserving = false;
|
|
162
162
|
|
|
163
163
|
function setNodeStatus(status) {
|
|
@@ -223,9 +223,9 @@ module.exports = function(RED) {
|
|
|
223
223
|
const observable = resolveConfiguredObservable(capabilityConfig);
|
|
224
224
|
if (observable) {
|
|
225
225
|
// Observables let the node collapse complex Protect payloads into
|
|
226
|
-
// a stable
|
|
226
|
+
// a stable typed value while preserving the original context in details.raw.
|
|
227
227
|
const observableValue = resolveObservableState(deviceType, payload, observable, node.currentObservableValue);
|
|
228
|
-
node.currentObservableValue =
|
|
228
|
+
node.currentObservableValue = observableValue;
|
|
229
229
|
|
|
230
230
|
const outputMsg = {
|
|
231
231
|
payload: node.currentObservableValue,
|
|
@@ -454,11 +454,11 @@ module.exports = function(RED) {
|
|
|
454
454
|
const observableScopeId = resolveConfiguredObservableScope(capabilityConfig);
|
|
455
455
|
if (observable) {
|
|
456
456
|
// When the user selected an observable, events can update the
|
|
457
|
-
//
|
|
457
|
+
// state output directly instead of only the event payload.
|
|
458
458
|
const observation = resolveObservableEventValue(node.deviceType, item, observable, observableScopeId);
|
|
459
459
|
if (observation.matched) {
|
|
460
460
|
const resolvedDeviceName = resolveOutputDeviceName(node.currentDevice);
|
|
461
|
-
node.currentObservableValue =
|
|
461
|
+
node.currentObservableValue = observation.value;
|
|
462
462
|
setNodeStatus({ fill: "blue", shape: "ring", text: `${item.type || "event"}` });
|
|
463
463
|
const stateMsg = {
|
|
464
464
|
payload: node.currentObservableValue,
|
|
@@ -15,6 +15,85 @@ const DEVICE_TYPE_DEFINITIONS = {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const ALL_OBSERVABLE_VALUE = "all";
|
|
19
|
+
const ALL_OBSERVABLE_OPTION = { value: ALL_OBSERVABLE_VALUE, label: "All" };
|
|
20
|
+
|
|
21
|
+
// Official UniFi Access events documented in:
|
|
22
|
+
// - 11.2 List of Supported Webhook Events
|
|
23
|
+
// - 11.1 Fetch Notifications [WebSocket] examples
|
|
24
|
+
const ACCESS_OBSERVABLE_DEFINITIONS = [
|
|
25
|
+
{
|
|
26
|
+
id: "doorbellIncoming",
|
|
27
|
+
label: "Doorbell Incoming",
|
|
28
|
+
eventPatterns: ["access.doorbell.incoming.*"]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "doorbellIncomingRen",
|
|
32
|
+
label: "Doorbell Incoming (REN)",
|
|
33
|
+
eventPatterns: ["access.doorbell.incoming.ren"]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "doorbellCompleted",
|
|
37
|
+
label: "Doorbell Completed",
|
|
38
|
+
eventPatterns: ["access.doorbell.completed"]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "doorUnlock",
|
|
42
|
+
label: "Door Unlock",
|
|
43
|
+
eventPatterns: ["access.door.unlock"]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "dpsStatus",
|
|
47
|
+
label: "DPS Status",
|
|
48
|
+
eventPatterns: ["access.device.dps_status"]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "emergencyStatus",
|
|
52
|
+
label: "Emergency Status",
|
|
53
|
+
eventPatterns: ["access.device.emergency_status"]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "unlockScheduleActivate",
|
|
57
|
+
label: "Unlock Schedule Activate",
|
|
58
|
+
eventPatterns: ["access.unlock_schedule.activate"]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "unlockScheduleDeactivate",
|
|
62
|
+
label: "Unlock Schedule Deactivate",
|
|
63
|
+
eventPatterns: ["access.unlock_schedule.deactivate"]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "temporaryUnlockStart",
|
|
67
|
+
label: "Temporary Unlock Start",
|
|
68
|
+
eventPatterns: ["access.temporary_unlock.start"]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "temporaryUnlockEnd",
|
|
72
|
+
label: "Temporary Unlock End",
|
|
73
|
+
eventPatterns: ["access.temporary_unlock.end"]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "visitorStatusChanged",
|
|
77
|
+
label: "Visitor Status Changed",
|
|
78
|
+
eventPatterns: ["access.visitor.status.changed"]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "remoteView",
|
|
82
|
+
label: "Remote View",
|
|
83
|
+
eventPatterns: ["access.remote_view"]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "remoteViewChange",
|
|
87
|
+
label: "Remote View Change",
|
|
88
|
+
eventPatterns: ["access.remote_view.change"]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "remoteDoorUnlock",
|
|
92
|
+
label: "Remote Door Unlock",
|
|
93
|
+
eventPatterns: ["access.data.device.remote_unlock"]
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
|
|
18
97
|
// Capabilities common to all Access resource families.
|
|
19
98
|
const COMMON_CAPABILITIES = [
|
|
20
99
|
{
|
|
@@ -266,6 +345,9 @@ async function getCapabilityOptions(deviceType, capabilityId, context) {
|
|
|
266
345
|
// Access capability options are currently static, but keep the async shape
|
|
267
346
|
// consistent with the other registries so the editor can treat them equally.
|
|
268
347
|
if (capabilityId === "observe") {
|
|
348
|
+
const capabilityConfig = normalizeObject(context && context.capabilityConfig);
|
|
349
|
+
const observableOptions = getAccessObservableOptions();
|
|
350
|
+
const selectedObservable = resolveSelectedAccessObservable(observableOptions, capabilityConfig.observable);
|
|
269
351
|
return {
|
|
270
352
|
capabilityId,
|
|
271
353
|
fields: [
|
|
@@ -273,11 +355,11 @@ async function getCapabilityOptions(deviceType, capabilityId, context) {
|
|
|
273
355
|
id: "observable",
|
|
274
356
|
label: "Event",
|
|
275
357
|
type: "select",
|
|
276
|
-
options:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
358
|
+
options: observableOptions,
|
|
359
|
+
defaultValue: selectedObservable,
|
|
360
|
+
helpText: selectedObservable === ALL_OBSERVABLE_VALUE
|
|
361
|
+
? "Emit all events for the selected Access device or door."
|
|
362
|
+
: "Emit only the selected official UniFi Access event type."
|
|
281
363
|
}
|
|
282
364
|
]
|
|
283
365
|
};
|
|
@@ -496,6 +578,60 @@ function matchesEvent(deviceType, deviceId, currentDevice, eventPayload) {
|
|
|
496
578
|
return false;
|
|
497
579
|
}
|
|
498
580
|
|
|
581
|
+
function getAccessObservableOptions() {
|
|
582
|
+
return [ALL_OBSERVABLE_OPTION].concat(
|
|
583
|
+
ACCESS_OBSERVABLE_DEFINITIONS.map((definition) => ({
|
|
584
|
+
value: definition.id,
|
|
585
|
+
label: definition.label
|
|
586
|
+
}))
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function resolveSelectedAccessObservable(options, configuredObservable) {
|
|
591
|
+
const normalized = String(configuredObservable || "").trim();
|
|
592
|
+
if (normalized && options.some((option) => option.value === normalized)) {
|
|
593
|
+
return normalized;
|
|
594
|
+
}
|
|
595
|
+
return ALL_OBSERVABLE_VALUE;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function normalizeEventName(value) {
|
|
599
|
+
return String(value || "").trim().toLowerCase();
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function matchesObservable(eventPayload, observable) {
|
|
603
|
+
const selected = String(observable || "").trim();
|
|
604
|
+
if (!selected || selected === ALL_OBSERVABLE_VALUE) {
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const definition = ACCESS_OBSERVABLE_DEFINITIONS.find((entry) => entry.id === selected);
|
|
609
|
+
if (!definition) {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const eventName = normalizeEventName(eventPayload && eventPayload.event);
|
|
614
|
+
if (!eventName) {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
return definition.eventPatterns.some((pattern) => matchesObservablePattern(eventName, pattern));
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function matchesObservablePattern(eventName, pattern) {
|
|
622
|
+
const normalizedPattern = normalizeEventName(pattern);
|
|
623
|
+
if (!normalizedPattern) {
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (normalizedPattern.endsWith(".*")) {
|
|
628
|
+
const base = normalizedPattern.slice(0, -2);
|
|
629
|
+
return eventName === base || eventName.startsWith(`${base}.`);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
return eventName === normalizedPattern;
|
|
633
|
+
}
|
|
634
|
+
|
|
499
635
|
function normalizeObject(value) {
|
|
500
636
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
501
637
|
? value
|
|
@@ -511,5 +647,6 @@ module.exports = {
|
|
|
511
647
|
getDeviceTypeDefinition,
|
|
512
648
|
getDeviceTypes,
|
|
513
649
|
matchesEvent,
|
|
650
|
+
matchesObservable,
|
|
514
651
|
summarizeDevice
|
|
515
652
|
};
|
|
@@ -138,6 +138,26 @@ const SENSOR_OBSERVABLE_DEFINITIONS = [
|
|
|
138
138
|
id: "extremeValues",
|
|
139
139
|
label: "Extreme values",
|
|
140
140
|
eventTypes: ["sensorExtremeValues"]
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: "temperature",
|
|
144
|
+
label: "Temperature",
|
|
145
|
+
eventTypes: []
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "humidity",
|
|
149
|
+
label: "Humidity",
|
|
150
|
+
eventTypes: []
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: "lightLevel",
|
|
154
|
+
label: "Light level",
|
|
155
|
+
eventTypes: []
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "batteryLevel",
|
|
159
|
+
label: "Battery level",
|
|
160
|
+
eventTypes: []
|
|
141
161
|
}
|
|
142
162
|
];
|
|
143
163
|
|
|
@@ -948,8 +968,8 @@ function buildAssetFileOptions(files) {
|
|
|
948
968
|
}
|
|
949
969
|
|
|
950
970
|
async function buildObservableFields(deviceType, context) {
|
|
951
|
-
// Observables let the generic "Receive Events" capability expose a
|
|
952
|
-
// boolean
|
|
971
|
+
// Observables let the generic "Receive Events" capability expose a typed
|
|
972
|
+
// value (boolean or number) tailored to the selected Protect device family.
|
|
953
973
|
const capabilityConfig = normalizeObject(context && context.capabilityConfig);
|
|
954
974
|
const observableOptions = getObservableOptions(deviceType);
|
|
955
975
|
const selectedObservable = resolveSelectedObservable(observableOptions, capabilityConfig.observable);
|
|
@@ -965,7 +985,7 @@ async function buildObservableFields(deviceType, context) {
|
|
|
965
985
|
? "Emit all events for the selected Protect device."
|
|
966
986
|
: selectedObservable
|
|
967
987
|
? buildObservableHelpText(deviceType, selectedObservable)
|
|
968
|
-
: "Select which
|
|
988
|
+
: "Select which observable value should be exposed on msg.payload."
|
|
969
989
|
}
|
|
970
990
|
];
|
|
971
991
|
|
|
@@ -1445,6 +1465,49 @@ function resolveSensorObservableState(sensor, observable, fallbackValue) {
|
|
|
1445
1465
|
"isExtremeValueDetected",
|
|
1446
1466
|
"extremeValueDetected",
|
|
1447
1467
|
"status.extremeValueDetected"
|
|
1468
|
+
]),
|
|
1469
|
+
temperature: () => firstDefinedValue(sensor, [
|
|
1470
|
+
"temperature",
|
|
1471
|
+
"status.temperature.value",
|
|
1472
|
+
"status.temperature",
|
|
1473
|
+
"stats.temperature.value",
|
|
1474
|
+
"stats.temperature",
|
|
1475
|
+
"environment.temperature",
|
|
1476
|
+
"sensorTemperature"
|
|
1477
|
+
]),
|
|
1478
|
+
humidity: () => firstDefinedValue(sensor, [
|
|
1479
|
+
"humidity",
|
|
1480
|
+
"status.humidity.value",
|
|
1481
|
+
"status.humidity",
|
|
1482
|
+
"stats.humidity.value",
|
|
1483
|
+
"stats.humidity",
|
|
1484
|
+
"environment.humidity",
|
|
1485
|
+
"sensorHumidity"
|
|
1486
|
+
]),
|
|
1487
|
+
lightLevel: () => firstDefinedValue(sensor, [
|
|
1488
|
+
"lightLevel",
|
|
1489
|
+
"light",
|
|
1490
|
+
"lux",
|
|
1491
|
+
"status.lightLevel",
|
|
1492
|
+
"status.light",
|
|
1493
|
+
"status.illuminance",
|
|
1494
|
+
"stats.lightLevel",
|
|
1495
|
+
"stats.light.value",
|
|
1496
|
+
"stats.light",
|
|
1497
|
+
"stats.illuminance.value",
|
|
1498
|
+
"stats.illuminance",
|
|
1499
|
+
"ambientLight"
|
|
1500
|
+
]),
|
|
1501
|
+
batteryLevel: () => firstDefinedValue(sensor, [
|
|
1502
|
+
"batteryLevel",
|
|
1503
|
+
"batteryPercentage",
|
|
1504
|
+
"batteryPercent",
|
|
1505
|
+
"battery.percentage",
|
|
1506
|
+
"batteryStatus.percentage",
|
|
1507
|
+
"status.batteryLevel",
|
|
1508
|
+
"status.batteryPercentage",
|
|
1509
|
+
"stats.battery.percentage",
|
|
1510
|
+
"stats.batteryLevel"
|
|
1448
1511
|
])
|
|
1449
1512
|
};
|
|
1450
1513
|
|
|
@@ -1456,6 +1519,10 @@ function resolveSensorObservableState(sensor, observable, fallbackValue) {
|
|
|
1456
1519
|
return fallbackValue;
|
|
1457
1520
|
}
|
|
1458
1521
|
|
|
1522
|
+
if (["temperature", "humidity", "lightLevel", "batteryLevel"].includes(observable)) {
|
|
1523
|
+
return normalizeNumericState(rawValue, fallbackValue);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1459
1526
|
return normalizeBooleanState(rawValue, fallbackValue);
|
|
1460
1527
|
}
|
|
1461
1528
|
|
|
@@ -1623,6 +1690,43 @@ function normalizeBooleanState(value, fallbackValue) {
|
|
|
1623
1690
|
return fallbackValue;
|
|
1624
1691
|
}
|
|
1625
1692
|
|
|
1693
|
+
function normalizeNumericState(value, fallbackValue) {
|
|
1694
|
+
if (typeof value === "number") {
|
|
1695
|
+
return Number.isFinite(value)
|
|
1696
|
+
? value
|
|
1697
|
+
: fallbackValue;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
if (typeof value === "string") {
|
|
1701
|
+
const normalized = value.trim().replace(",", ".");
|
|
1702
|
+
const match = normalized.match(/-?\d+(\.\d+)?/);
|
|
1703
|
+
if (match) {
|
|
1704
|
+
const parsed = Number.parseFloat(match[0]);
|
|
1705
|
+
if (Number.isFinite(parsed)) {
|
|
1706
|
+
return parsed;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
return fallbackValue;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1713
|
+
const nested = firstDefinedValue(value, [
|
|
1714
|
+
"value",
|
|
1715
|
+
"current",
|
|
1716
|
+
"reading",
|
|
1717
|
+
"level",
|
|
1718
|
+
"amount",
|
|
1719
|
+
"percent",
|
|
1720
|
+
"percentage"
|
|
1721
|
+
]);
|
|
1722
|
+
if (nested !== undefined) {
|
|
1723
|
+
return normalizeNumericState(nested, fallbackValue);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
return fallbackValue;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1626
1730
|
async function buildCameraObservableScopeField(context, selectedObservable, capabilityConfig) {
|
|
1627
1731
|
const scopeDefinition = CAMERA_OBSERVABLE_SCOPE_DEFINITIONS[String(selectedObservable || "").trim()];
|
|
1628
1732
|
if (!scopeDefinition) {
|
|
@@ -168,7 +168,7 @@ const TYPE_FIELD_METADATA = {
|
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
// Observable metadata powers the "Receive Events" helper text shown in the
|
|
171
|
-
// editor when the user chooses which
|
|
171
|
+
// editor when the user chooses which state/metric to expose.
|
|
172
172
|
const OBSERVABLE_METADATA = {
|
|
173
173
|
camera: {
|
|
174
174
|
ring: {
|
|
@@ -242,6 +242,26 @@ const OBSERVABLE_METADATA = {
|
|
|
242
242
|
label: "Extreme Values",
|
|
243
243
|
description: "True while the sensor is reporting an active extreme-values event.",
|
|
244
244
|
source: "official"
|
|
245
|
+
},
|
|
246
|
+
temperature: {
|
|
247
|
+
label: "Temperature",
|
|
248
|
+
description: "Current ambient temperature reported by the sensor.",
|
|
249
|
+
source: "official"
|
|
250
|
+
},
|
|
251
|
+
humidity: {
|
|
252
|
+
label: "Humidity",
|
|
253
|
+
description: "Current relative humidity reported by the sensor.",
|
|
254
|
+
source: "official"
|
|
255
|
+
},
|
|
256
|
+
lightLevel: {
|
|
257
|
+
label: "Light Level",
|
|
258
|
+
description: "Current ambient light level reported by the sensor.",
|
|
259
|
+
source: "inferred"
|
|
260
|
+
},
|
|
261
|
+
batteryLevel: {
|
|
262
|
+
label: "Battery Level",
|
|
263
|
+
description: "Current battery percentage reported by the sensor.",
|
|
264
|
+
source: "inferred"
|
|
245
265
|
}
|
|
246
266
|
},
|
|
247
267
|
light: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-unifi-ultimate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Node-RED nodes for Ubiquiti UniFi integrations, including UniFi Protect, UniFi Access, and UniFi Network.",
|
|
5
5
|
"files": [
|
|
6
6
|
"nodes/",
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
"bugs": {
|
|
61
61
|
"url": "https://github.com/Supergiovane/node-red-contrib-unifi-ultimate/issues"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|