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
package/README.md
CHANGED
|
@@ -72,6 +72,10 @@ Use Network nodes to work with:
|
|
|
72
72
|
Common uses:
|
|
73
73
|
|
|
74
74
|
- Check whether a client is online.
|
|
75
|
+
- Count online clients for a site.
|
|
76
|
+
- Create simple guest vouchers.
|
|
77
|
+
- Read CPU, memory, and uptime from UniFi devices.
|
|
78
|
+
- Read Temperatures when the selected UniFi device exposes thermal sensor data.
|
|
75
79
|
- Restart a UniFi device.
|
|
76
80
|
- Power-cycle a PoE port.
|
|
77
81
|
- Turn PoE on or off for a selected switch port.
|
|
@@ -81,6 +85,7 @@ Editor conveniences:
|
|
|
81
85
|
|
|
82
86
|
- Device and client fields are searchable.
|
|
83
87
|
- Port lists show port status and connected clients when UniFi exposes that information.
|
|
88
|
+
- Read-only actions can emit periodically to simulate a simple polling stream.
|
|
84
89
|
- Selecting an item updates the node `Name` automatically.
|
|
85
90
|
|
|
86
91
|
<br/>
|
|
@@ -111,7 +116,7 @@ Common uses:
|
|
|
111
116
|
- Switch viewer live views.
|
|
112
117
|
- Update supported device properties.
|
|
113
118
|
|
|
114
|
-
For supported observables, the node can output
|
|
119
|
+
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
120
|
|
|
116
121
|
<br/>
|
|
117
122
|
<br/>
|
|
@@ -143,6 +148,7 @@ Common uses:
|
|
|
143
148
|
Most nodes send the result on output 1.
|
|
144
149
|
|
|
145
150
|
Protect and Access device nodes emit both state and live event messages on the same output pin when `Receive Events` is selected.
|
|
151
|
+
On Access nodes, the `Event` selector can filter the stream to official UniFi Access event families, or use `All` for full passthrough.
|
|
146
152
|
|
|
147
153
|
Useful metadata is attached to the output message, for example:
|
|
148
154
|
|
|
@@ -183,6 +189,31 @@ When `msg.payload` is an object, it also includes `payload.deviceName` with the
|
|
|
183
189
|
}
|
|
184
190
|
```
|
|
185
191
|
|
|
192
|
+
`Unifi Network Device` action `Read Temperatures` returns:
|
|
193
|
+
|
|
194
|
+
| Field | Type | Guaranteed | Notes |
|
|
195
|
+
| ---------------------------------- | ------ | ---------- | ----------------------------------------------------------- |
|
|
196
|
+
| `msg.payload` | number | no | First normalized temperature reading in Celsius. |
|
|
197
|
+
| `msg.details.temperature` | object | yes | Full normalized temperature details and all readings found. |
|
|
198
|
+
| `msg.details.temperatureSources[]` | array | yes | Sources used, for example `official` and/or `legacy`. |
|
|
199
|
+
|
|
200
|
+
Some switch models and controller versions do not expose temperature data; in that case the action emits `msg.payload = null` and details include `hasTemperatures: false`.
|
|
201
|
+
|
|
202
|
+
Other simple `Unifi Network Device` actions return compact payloads:
|
|
203
|
+
|
|
204
|
+
| Action | `msg.payload` | Details |
|
|
205
|
+
| ---------------------- | ------------------------------- | ----------------------------- |
|
|
206
|
+
| `Is Client Online` | `true` or `false` | `msg.details.client` |
|
|
207
|
+
| `Count Online Clients` | online client count | `msg.details.onlineClients[]` |
|
|
208
|
+
| `Read CPU` | CPU percentage | `msg.details.statistics` |
|
|
209
|
+
| `Read Memory` | memory percentage | `msg.details.statistics` |
|
|
210
|
+
| `Read Uptime` | uptime in seconds | `msg.details.statistics` |
|
|
211
|
+
| `Create Guest Voucher` | one voucher code, or code array | `msg.details.vouchers[]` |
|
|
212
|
+
|
|
213
|
+
For read-only actions on Network, Protect, and Access device nodes, enable `Emit periodically` to send the configured result at a fixed interval without using an Inject node. This option is hidden for event streams and write actions.
|
|
214
|
+
|
|
215
|
+
Request timeouts are handled internally. Existing nodes do not need timeout settings, and Network PoE power polling uses a 15 second default when the shared config value is left empty.
|
|
216
|
+
|
|
186
217
|
### Unifi Network Presence
|
|
187
218
|
|
|
188
219
|
```json
|
|
@@ -293,13 +324,13 @@ Power fields for `Unifi Network Control POE`:
|
|
|
293
324
|
|
|
294
325
|
Import from `examples/`:
|
|
295
326
|
|
|
296
|
-
| Flow file | What it demonstrates
|
|
297
|
-
| -------------------------------------------------------------------------------------------- |
|
|
298
|
-
| [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-camera-actions.json](examples/unifi-protect-camera-actions.json) | Snapshot, PTZ presets, and doorbell messages
|
|
301
|
-
| [examples/unifi-access-door-control.json](examples/unifi-access-door-control.json) | Door state, unlock, and temporary lock rule
|
|
302
|
-
| [examples/unifi-access-intercom-doorbell.json](examples/unifi-access-intercom-doorbell.json) | Intercom observe, trigger, and cancel doorbell
|
|
327
|
+
| Flow file | What it demonstrates |
|
|
328
|
+
| -------------------------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
329
|
+
| [examples/unifi-protect-info.json](examples/unifi-protect-info.json) | Read Protect camera state |
|
|
330
|
+
| [examples/unifi-protect-sensor-observe.json](examples/unifi-protect-sensor-observe.json) | Receive sensor observables (boolean or numeric) |
|
|
331
|
+
| [examples/unifi-protect-camera-actions.json](examples/unifi-protect-camera-actions.json) | Snapshot, PTZ presets, and doorbell messages |
|
|
332
|
+
| [examples/unifi-access-door-control.json](examples/unifi-access-door-control.json) | Door state, unlock, and temporary lock rule |
|
|
333
|
+
| [examples/unifi-access-intercom-doorbell.json](examples/unifi-access-intercom-doorbell.json) | Intercom observe, trigger, and cancel doorbell |
|
|
303
334
|
|
|
304
335
|
## Notes
|
|
305
336
|
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
return this.name || this.host || "Unifi Access Config";
|
|
16
16
|
},
|
|
17
17
|
oneditprepare: function () {
|
|
18
|
-
const
|
|
18
|
+
const node = this;
|
|
19
|
+
const $hostInput = $("#node-config-input-host");
|
|
19
20
|
const $apiToken = $("#node-config-input-apiToken");
|
|
20
21
|
const $rejectUnauthorized = $("#node-config-input-rejectUnauthorized");
|
|
21
22
|
const $apiTokenRow = $apiToken.closest(".form-row");
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
const $advancedRow = $("#node-config-row-advanced");
|
|
24
25
|
|
|
25
26
|
function syncProgressiveRows() {
|
|
26
|
-
const hasHost = String($
|
|
27
|
+
const hasHost = String($hostInput.val() || node.host || "").trim() !== "";
|
|
27
28
|
$apiTokenRow.toggle(hasHost);
|
|
28
29
|
$securityRow.toggle(hasHost);
|
|
29
30
|
$advancedRow.toggle(hasHost);
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
|
|
39
40
|
syncProgressiveRows();
|
|
40
41
|
|
|
41
|
-
$
|
|
42
|
+
$hostInput.on("change input", function () {
|
|
42
43
|
syncProgressiveRows();
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
inputs: { value: 1 },
|
|
15
15
|
capability: { value: "observe", required: true },
|
|
16
16
|
capabilityConfig: { value: "{}" },
|
|
17
|
-
|
|
17
|
+
autoEmit: { value: false },
|
|
18
|
+
autoEmitInterval: { value: 60, validate: RED.validators.number() }
|
|
18
19
|
},
|
|
19
20
|
inputs: 1,
|
|
20
21
|
outputs: 1,
|
|
@@ -28,8 +29,11 @@
|
|
|
28
29
|
const selectedCapabilityId = String($("#node-input-capability").val() || this.capability || "observe").trim();
|
|
29
30
|
const selectedCapabilityOpensStream = $("#node-input-capability option:selected").data("opens-stream") === true
|
|
30
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 || selectedCapabilityMethod === "GET");
|
|
31
34
|
// Hide the input pin only when the selected action starts an event stream.
|
|
32
35
|
this.inputs = (selectedCapabilityOpensStream || selectedCapabilityId === "observe") ? 0 : 1;
|
|
36
|
+
this.autoEmit = supportsPeriodicEmit ? $("#node-input-autoEmit").is(":checked") : false;
|
|
33
37
|
|
|
34
38
|
const $capabilityConfig = $("#node-input-capabilityConfig");
|
|
35
39
|
const capabilityConfig = {};
|
|
@@ -85,6 +89,9 @@
|
|
|
85
89
|
const $capabilityConfig = $("#node-input-capabilityConfig");
|
|
86
90
|
const $capabilityConfigRow = $("#node-row-capabilityConfig");
|
|
87
91
|
const $capabilityConfigContainer = $("#node-input-capabilityConfigContainer");
|
|
92
|
+
const $autoEmit = $("#node-input-autoEmit");
|
|
93
|
+
const $autoEmitRow = $("#node-row-autoEmit");
|
|
94
|
+
const $autoEmitIntervalRow = $("#node-row-autoEmitInterval");
|
|
88
95
|
const $refresh = $("#node-input-refreshDevices");
|
|
89
96
|
const $deviceTypeRow = $deviceType.closest(".form-row");
|
|
90
97
|
const $deviceIdRow = $deviceId.closest(".form-row");
|
|
@@ -95,6 +102,7 @@
|
|
|
95
102
|
let capabilityOptionsRequestId = 0;
|
|
96
103
|
let suspendChangeHandling = false;
|
|
97
104
|
let isInitializingEditor = true;
|
|
105
|
+
let restoredPersistedAutoEmit = false;
|
|
98
106
|
let deviceTypeDefinitions = [];
|
|
99
107
|
let capabilityDefinitions = [];
|
|
100
108
|
|
|
@@ -109,12 +117,30 @@
|
|
|
109
117
|
const hasDevice = hasSelection($deviceId);
|
|
110
118
|
const hasCapability = hasSelection($capability);
|
|
111
119
|
const hasCapabilityFields = $capabilityConfigRow.data("has-fields") === true;
|
|
120
|
+
const capabilityDefinition = getSelectedCapabilityDefinition();
|
|
121
|
+
const capabilityMethod = String(capabilityDefinition && capabilityDefinition.method || "").trim().toUpperCase();
|
|
122
|
+
const supportsPeriodicEmit = capabilityDefinition
|
|
123
|
+
&& capabilityDefinition.opensEventStream !== true
|
|
124
|
+
&& (!capabilityMethod || capabilityMethod === "GET");
|
|
125
|
+
const showPeriodicEmit = Boolean(hasServer && hasDeviceType && hasDevice && hasCapability && supportsPeriodicEmit);
|
|
112
126
|
|
|
113
127
|
$deviceTypeRow.toggle(hasServer);
|
|
114
128
|
$deviceIdRow.toggle(hasServer && hasDeviceType);
|
|
115
129
|
$capabilityRow.toggle(hasServer && hasDeviceType && hasDevice);
|
|
116
130
|
$capabilityConfigRow.toggle(hasServer && hasDeviceType && hasDevice && hasCapability && hasCapabilityFields);
|
|
117
131
|
$advancedRow.toggle(hasServer && hasDeviceType && hasDevice && hasCapability);
|
|
132
|
+
$autoEmitRow.toggle(showPeriodicEmit);
|
|
133
|
+
$autoEmitIntervalRow.toggle(showPeriodicEmit && $autoEmit.is(":checked"));
|
|
134
|
+
|
|
135
|
+
if (showPeriodicEmit && !restoredPersistedAutoEmit) {
|
|
136
|
+
$autoEmit.prop("checked", node.autoEmit === true || node.autoEmit === "true");
|
|
137
|
+
restoredPersistedAutoEmit = true;
|
|
138
|
+
$autoEmitIntervalRow.toggle($autoEmit.is(":checked"));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!showPeriodicEmit && !isInitializingEditor) {
|
|
142
|
+
$autoEmit.prop("checked", false);
|
|
143
|
+
}
|
|
118
144
|
}
|
|
119
145
|
|
|
120
146
|
function parseCapabilityConfig(rawValue) {
|
|
@@ -575,6 +601,7 @@
|
|
|
575
601
|
$capability.append(
|
|
576
602
|
$("<option></option>")
|
|
577
603
|
.val(item.id)
|
|
604
|
+
.attr("data-method", String(item.method || "").trim())
|
|
578
605
|
.attr("data-opens-stream", item.opensEventStream === true ? "true" : "false")
|
|
579
606
|
.text(item.label)
|
|
580
607
|
);
|
|
@@ -1032,6 +1059,9 @@
|
|
|
1032
1059
|
writeCapabilityConfig();
|
|
1033
1060
|
refreshAfterCapabilityChange();
|
|
1034
1061
|
});
|
|
1062
|
+
$autoEmit.on("change", function () {
|
|
1063
|
+
syncProgressiveRows();
|
|
1064
|
+
});
|
|
1035
1065
|
$refresh.on("click", function (event) {
|
|
1036
1066
|
event.preventDefault();
|
|
1037
1067
|
refreshAfterServerChange();
|
|
@@ -1084,9 +1114,15 @@
|
|
|
1084
1114
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
1085
1115
|
<input type="text" id="node-input-name" placeholder="Node name">
|
|
1086
1116
|
</div>
|
|
1087
|
-
<div class="form-row">
|
|
1088
|
-
<label for="node-input-
|
|
1089
|
-
<input type="
|
|
1117
|
+
<div class="form-row" id="node-row-autoEmit">
|
|
1118
|
+
<label for="node-input-autoEmit"><i class="fa fa-repeat"></i> Repeat</label>
|
|
1119
|
+
<input type="checkbox" id="node-input-autoEmit" style="display:inline-block; width:auto; vertical-align:top;">
|
|
1120
|
+
<span style="margin-left:8px;">Emit periodically</span>
|
|
1121
|
+
</div>
|
|
1122
|
+
<div class="form-row" id="node-row-autoEmitInterval">
|
|
1123
|
+
<label for="node-input-autoEmitInterval"><i class="fa fa-clock-o"></i> Every</label>
|
|
1124
|
+
<input type="number" id="node-input-autoEmitInterval" min="5" step="1" placeholder="60" style="width:120px;">
|
|
1125
|
+
<span style="margin-left:8px;">seconds</span>
|
|
1090
1126
|
</div>
|
|
1091
1127
|
</div>
|
|
1092
1128
|
</script>
|
|
@@ -1102,10 +1138,12 @@
|
|
|
1102
1138
|
<p><b>Action</b> only shows actions supported by the selected item.</p>
|
|
1103
1139
|
<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
1140
|
<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>
|
|
1141
|
+
<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
1142
|
<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
1143
|
<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
|
-
<p><b>
|
|
1144
|
+
<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>
|
|
1145
|
+
<p>Request timeout is handled automatically by the node.</p>
|
|
1146
|
+
<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>
|
|
1109
1147
|
|
|
1110
1148
|
<h3>Input</h3>
|
|
1111
1149
|
<ul>
|
|
@@ -5,9 +5,11 @@ 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");
|
|
12
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
|
|
11
13
|
|
|
12
14
|
function resolveDeviceType(configuredDeviceType) {
|
|
13
15
|
return String(configuredDeviceType || "").trim();
|
|
@@ -44,6 +46,18 @@ function resolveCapabilityConfig(configuredCapabilityConfig) {
|
|
|
44
46
|
return parseCapabilityConfig(configuredCapabilityConfig);
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
function parseBoolean(value) {
|
|
50
|
+
return value === true || value === "true" || value === 1 || value === "1";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function parseIntervalSeconds(value, fallback) {
|
|
54
|
+
const numeric = Number(value);
|
|
55
|
+
if (!Number.isFinite(numeric) || numeric < 5) {
|
|
56
|
+
return fallback;
|
|
57
|
+
}
|
|
58
|
+
return Math.trunc(numeric);
|
|
59
|
+
}
|
|
60
|
+
|
|
47
61
|
function buildNodeStatus(deviceType, payload) {
|
|
48
62
|
const normalizedType = String(deviceType || "").trim();
|
|
49
63
|
const item = payload && typeof payload === "object" ? payload : {};
|
|
@@ -127,6 +141,14 @@ function appendStatusTimestamp(text) {
|
|
|
127
141
|
return normalized ? `${normalized} ${suffix}` : suffix;
|
|
128
142
|
}
|
|
129
143
|
|
|
144
|
+
function resolveConfiguredObservable(capabilityConfig) {
|
|
145
|
+
return String(
|
|
146
|
+
capabilityConfig && capabilityConfig.observable !== undefined
|
|
147
|
+
? capabilityConfig.observable
|
|
148
|
+
: "all"
|
|
149
|
+
).trim() || "all";
|
|
150
|
+
}
|
|
151
|
+
|
|
130
152
|
module.exports = function(RED) {
|
|
131
153
|
function UnifiAccessDeviceNode(config) {
|
|
132
154
|
RED.nodes.createNode(this, config);
|
|
@@ -138,8 +160,12 @@ module.exports = function(RED) {
|
|
|
138
160
|
node.deviceId = config.deviceId || "";
|
|
139
161
|
node.capability = config.capability || "observe";
|
|
140
162
|
node.capabilityConfig = config.capabilityConfig || "{}";
|
|
163
|
+
node.autoEmit = parseBoolean(config.autoEmit);
|
|
164
|
+
node.autoEmitIntervalSeconds = parseIntervalSeconds(config.autoEmitInterval, 60);
|
|
165
|
+
node.autoEmitTimer = null;
|
|
166
|
+
node.autoEmitInFlight = false;
|
|
141
167
|
node.deviceName = resolveDeviceName(config.deviceName);
|
|
142
|
-
node.timeout =
|
|
168
|
+
node.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
143
169
|
node.currentDevice = null;
|
|
144
170
|
node.isObserving = false;
|
|
145
171
|
|
|
@@ -220,7 +246,7 @@ module.exports = function(RED) {
|
|
|
220
246
|
sendOutputs(send, stateMsg, null);
|
|
221
247
|
}
|
|
222
248
|
|
|
223
|
-
async function invokeCapability(send) {
|
|
249
|
+
async function invokeCapability(send, triggerSource) {
|
|
224
250
|
if (!node.server) {
|
|
225
251
|
throw new Error("Unifi Access configuration is missing.");
|
|
226
252
|
}
|
|
@@ -305,7 +331,7 @@ module.exports = function(RED) {
|
|
|
305
331
|
deviceId,
|
|
306
332
|
capabilityId,
|
|
307
333
|
send,
|
|
308
|
-
capability.mode === "fetch" ? "fetch" : "manual-refresh"
|
|
334
|
+
triggerSource || (capability.mode === "fetch" ? "fetch" : "manual-refresh")
|
|
309
335
|
);
|
|
310
336
|
return;
|
|
311
337
|
}
|
|
@@ -390,6 +416,16 @@ module.exports = function(RED) {
|
|
|
390
416
|
return resolveCapabilityId(node.capability) === "observe";
|
|
391
417
|
}
|
|
392
418
|
|
|
419
|
+
function configuredCapabilitySupportsAutoEmit() {
|
|
420
|
+
const capability = resolveConfiguredCapabilityDefinition();
|
|
421
|
+
if (!capability || capability.opensEventStream === true) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const method = String(capability.method || "").trim().toUpperCase();
|
|
426
|
+
return !method || method === "GET";
|
|
427
|
+
}
|
|
428
|
+
|
|
393
429
|
function shouldObserveConfiguredDevice() {
|
|
394
430
|
return node.server && configuredCapabilityOpensEventStream() && node.deviceType && node.deviceId;
|
|
395
431
|
}
|
|
@@ -407,13 +443,57 @@ module.exports = function(RED) {
|
|
|
407
443
|
});
|
|
408
444
|
}
|
|
409
445
|
|
|
446
|
+
function stopAutoEmitTimer() {
|
|
447
|
+
if (node.autoEmitTimer) {
|
|
448
|
+
clearInterval(node.autoEmitTimer);
|
|
449
|
+
node.autoEmitTimer = null;
|
|
450
|
+
}
|
|
451
|
+
node.autoEmitInFlight = false;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function shouldStartAutoEmitTimer() {
|
|
455
|
+
return Boolean(
|
|
456
|
+
node.server
|
|
457
|
+
&& node.autoEmit
|
|
458
|
+
&& node.deviceType
|
|
459
|
+
&& node.deviceId
|
|
460
|
+
&& configuredCapabilitySupportsAutoEmit()
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function runAutoEmit() {
|
|
465
|
+
if (node.autoEmitInFlight || !shouldStartAutoEmitTimer()) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
node.autoEmitInFlight = true;
|
|
470
|
+
invokeCapability(node.send.bind(node), "interval")
|
|
471
|
+
.catch((error) => {
|
|
472
|
+
setNodeStatus({ fill: "red", shape: "ring", text: "auto error" });
|
|
473
|
+
node.error(error);
|
|
474
|
+
})
|
|
475
|
+
.finally(() => {
|
|
476
|
+
node.autoEmitInFlight = false;
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function startAutoEmitTimer() {
|
|
481
|
+
stopAutoEmitTimer();
|
|
482
|
+
if (!shouldStartAutoEmitTimer()) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
node.autoEmitTimer = setInterval(runAutoEmit, node.autoEmitIntervalSeconds * 1000);
|
|
487
|
+
setNodeStatus({ fill: "grey", shape: "ring", text: `every ${node.autoEmitIntervalSeconds}s` });
|
|
488
|
+
}
|
|
489
|
+
|
|
410
490
|
node.on("input", async function(_msg, send, done) {
|
|
411
491
|
send = send || function() {
|
|
412
492
|
node.send.apply(node, arguments);
|
|
413
493
|
};
|
|
414
494
|
|
|
415
495
|
try {
|
|
416
|
-
await invokeCapability(send);
|
|
496
|
+
await invokeCapability(send, "manual-refresh");
|
|
417
497
|
if (typeof done === "function") {
|
|
418
498
|
done();
|
|
419
499
|
}
|
|
@@ -434,6 +514,11 @@ module.exports = function(RED) {
|
|
|
434
514
|
if (!node.isObserving || !matchesEvent(node.deviceType, node.deviceId, node.currentDevice, eventPayload)) {
|
|
435
515
|
return;
|
|
436
516
|
}
|
|
517
|
+
const capabilityConfig = parseCapabilityConfig(node.capabilityConfig);
|
|
518
|
+
const observable = resolveConfiguredObservable(capabilityConfig);
|
|
519
|
+
if (!matchesObservable(eventPayload, observable)) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
437
522
|
const eventName = String(eventPayload.event || "").trim();
|
|
438
523
|
|
|
439
524
|
setNodeStatus({ fill: "blue", shape: "ring", text: eventName || "event" });
|
|
@@ -449,7 +534,8 @@ module.exports = function(RED) {
|
|
|
449
534
|
device: node.currentDevice,
|
|
450
535
|
unifiAccess: buildBaseMetadata(node.deviceType, node.deviceId, "observe", {
|
|
451
536
|
source: "events",
|
|
452
|
-
eventType: eventName
|
|
537
|
+
eventType: eventName,
|
|
538
|
+
observable: observable === "all" ? undefined : observable
|
|
453
539
|
})
|
|
454
540
|
});
|
|
455
541
|
sendOutputs(node.send.bind(node), null, eventMsg);
|
|
@@ -466,10 +552,12 @@ module.exports = function(RED) {
|
|
|
466
552
|
node.server.addClient(node);
|
|
467
553
|
}
|
|
468
554
|
startObservation();
|
|
555
|
+
startAutoEmitTimer();
|
|
469
556
|
}
|
|
470
557
|
|
|
471
558
|
node.on("close", function(done) {
|
|
472
559
|
try {
|
|
560
|
+
stopAutoEmitTimer();
|
|
473
561
|
if (node.server && typeof node.server.removeClient === "function") {
|
|
474
562
|
node.server.removeClient(node);
|
|
475
563
|
}
|
|
@@ -8,7 +8,16 @@
|
|
|
8
8
|
name: { value: "Unifi Network Config" },
|
|
9
9
|
host: { value: "", required: true },
|
|
10
10
|
rejectUnauthorized: { value: false },
|
|
11
|
-
powerObservationIntervalSeconds: {
|
|
11
|
+
powerObservationIntervalSeconds: {
|
|
12
|
+
value: 15,
|
|
13
|
+
required: false,
|
|
14
|
+
validate: function (value) {
|
|
15
|
+
return value === undefined
|
|
16
|
+
|| value === null
|
|
17
|
+
|| value === ""
|
|
18
|
+
|| RED.validators.number()(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
12
21
|
},
|
|
13
22
|
credentials: {
|
|
14
23
|
apiKey: { type: "password", required: true }
|
|
@@ -17,7 +26,8 @@
|
|
|
17
26
|
return this.name || this.host || "Unifi Network Config";
|
|
18
27
|
},
|
|
19
28
|
oneditprepare: function () {
|
|
20
|
-
const
|
|
29
|
+
const node = this;
|
|
30
|
+
const $hostInput = $("#node-config-input-host");
|
|
21
31
|
const $apiKey = $("#node-config-input-apiKey");
|
|
22
32
|
const $rejectUnauthorized = $("#node-config-input-rejectUnauthorized");
|
|
23
33
|
const $powerObservationIntervalSeconds = $("#node-config-input-powerObservationIntervalSeconds");
|
|
@@ -27,7 +37,7 @@
|
|
|
27
37
|
const $advancedRow = $("#node-config-row-advanced");
|
|
28
38
|
|
|
29
39
|
function syncProgressiveRows() {
|
|
30
|
-
const hasHost = String($
|
|
40
|
+
const hasHost = String($hostInput.val() || node.host || "").trim() !== "";
|
|
31
41
|
$apiKeyRow.toggle(hasHost);
|
|
32
42
|
$securityRow.toggle(hasHost);
|
|
33
43
|
$powerObservationRow.toggle(hasHost);
|
|
@@ -42,7 +52,7 @@
|
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
syncProgressiveRows();
|
|
45
|
-
$
|
|
55
|
+
$hostInput.on("change input", function () {
|
|
46
56
|
syncProgressiveRows();
|
|
47
57
|
});
|
|
48
58
|
}
|
|
@@ -93,7 +103,7 @@
|
|
|
93
103
|
<p><b>Controller</b> accepts the UniFi OS host or IP address. The node builds the local UniFi Network proxy URL automatically.</p>
|
|
94
104
|
<p><b>API Key</b> is required for authentication and is sent as <code>X-API-Key</code>.</p>
|
|
95
105
|
<p><b>Security</b> controls certificate verification. Disable it only when your controller uses a self-signed certificate.</p>
|
|
96
|
-
<p><b>Power Poll (s)</b> is the global polling interval used by all <code>Control POE</code> nodes when action is <code>Emit Power Consumption</code
|
|
106
|
+
<p><b>Power Poll (s)</b> is the global polling interval used by all <code>Control POE</code> nodes when action is <code>Emit Power Consumption</code>. It is optional and defaults to 15 seconds.</p>
|
|
97
107
|
<p><b>Name</b> is the config node name shown in the editor.</p>
|
|
98
108
|
|
|
99
109
|
<h3>Usage</h3>
|