node-red-contrib-unifi-ultimate 1.0.6 → 1.0.7
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
CHANGED
|
@@ -75,6 +75,7 @@ Use **Network** nodes to work with:
|
|
|
75
75
|
Things you can do:
|
|
76
76
|
|
|
77
77
|
- Check whether a device or phone is connected to your network.
|
|
78
|
+
- 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).
|
|
78
79
|
- Count how many clients are currently online.
|
|
79
80
|
- Create guest Wi-Fi vouchers.
|
|
80
81
|
- Read CPU usage, memory, and uptime from a switch or access point.
|
|
@@ -145,7 +146,7 @@ Every node has **two outputs**:
|
|
|
145
146
|
|
|
146
147
|
When an error occurs, the node status turns red and the error message comes out of the second output. Connect it to a **debug** node to see what happened, or wire it to any notification logic in your flow.
|
|
147
148
|
|
|
148
|
-
**Repeat periodically** — for read actions, you can tick *Emit periodically* in the node editor to have the node send the result automatically at a fixed interval, without needing an Inject node.
|
|
149
|
+
**Repeat periodically** — for read actions, you can tick *Emit periodically* in the node editor to have the node send the result automatically at a fixed interval, without needing an Inject node. The **Presence Detection** node offers a similar **Resend (s)** field: set it above `0` to re-emit the last known presence value on that cadence (even when unchanged). Resent messages carry `msg.eventName = "repeat"` so you can tell them apart from real state changes; leave it at `0` to disable.
|
|
149
150
|
|
|
150
151
|
## Example Flows
|
|
151
152
|
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
deviceName: { value: "" },
|
|
13
13
|
pollInterval: { value: 10, required: true, validate: RED.validators.number() },
|
|
14
14
|
onlineHysteresis: { value: 15, required: true, validate: RED.validators.number() },
|
|
15
|
-
offlineHysteresis: { value: 30, required: true, validate: RED.validators.number() }
|
|
15
|
+
offlineHysteresis: { value: 30, required: true, validate: RED.validators.number() },
|
|
16
|
+
repeatInterval: { value: 0, required: false, validate: RED.validators.number() }
|
|
16
17
|
},
|
|
17
18
|
inputs: 0,
|
|
18
19
|
outputs: 2,
|
|
@@ -512,6 +513,10 @@
|
|
|
512
513
|
<label for="node-input-offlineHysteresis"><i class="fa fa-hourglass-half"></i> Hysteresis (s)</label>
|
|
513
514
|
<input type="text" id="node-input-offlineHysteresis" placeholder="30">
|
|
514
515
|
</div>
|
|
516
|
+
<div class="form-row">
|
|
517
|
+
<label for="node-input-repeatInterval"><i class="fa fa-clock-o"></i> Resend (s)</label>
|
|
518
|
+
<input type="text" id="node-input-repeatInterval" placeholder="0 = off">
|
|
519
|
+
</div>
|
|
515
520
|
<input type="hidden" id="node-input-deviceName">
|
|
516
521
|
</div>
|
|
517
522
|
</script>
|
|
@@ -527,6 +532,7 @@
|
|
|
527
532
|
<p><b>Poll (s)</b> sets this node cadence for presence checks. Scheduling and fetch execution are handled by the shared Network config node.</p>
|
|
528
533
|
<p><b>Connect Hysteresis (s)</b> delays the <code>true</code> output so brief reconnects do not flap.</p>
|
|
529
534
|
<p><b>Hysteresis (s)</b> delays the <code>false</code> output to avoid flapping when the client disconnects briefly.</p>
|
|
535
|
+
<p><b>Resend (s)</b> optionally re-emits the last saved presence value on a fixed cadence, even when it has not changed. Leave it at <code>0</code> to disable (default). Repeated messages carry <code>msg.eventName = "repeat"</code> so you can tell them apart from state changes.</p>
|
|
530
536
|
<p>Request timeout is handled automatically by the node.</p>
|
|
531
537
|
<p><b>Name</b> is the node name shown in the editor and is updated only when you manually select a different client from the list.</p>
|
|
532
538
|
|
|
@@ -45,10 +45,14 @@ module.exports = function(RED) {
|
|
|
45
45
|
node.pollIntervalSeconds = parsePositiveSeconds(config.pollInterval, 10);
|
|
46
46
|
node.onlineHysteresisSeconds = parseNonNegativeSeconds(config.onlineHysteresis, 15);
|
|
47
47
|
node.offlineHysteresisSeconds = parseNonNegativeSeconds(config.offlineHysteresis, 30);
|
|
48
|
+
// Optional "resend" timer: when > 0 the last saved presence value is
|
|
49
|
+
// re-emitted on this cadence even if it has not changed. 0 disables it.
|
|
50
|
+
node.repeatIntervalSeconds = parseNonNegativeSeconds(config.repeatInterval, 0);
|
|
48
51
|
node.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
49
52
|
node.deviceName = resolveDeviceName(config.deviceName);
|
|
50
53
|
|
|
51
54
|
node.isObserving = false;
|
|
55
|
+
node.repeatTimer = null;
|
|
52
56
|
node.currentPresence = null;
|
|
53
57
|
node.lastConnectedAt = 0;
|
|
54
58
|
node.firstOnlineDetectedAt = 0;
|
|
@@ -108,6 +112,7 @@ module.exports = function(RED) {
|
|
|
108
112
|
pollIntervalSeconds: node.pollIntervalSeconds,
|
|
109
113
|
onlineHysteresisSeconds: node.onlineHysteresisSeconds,
|
|
110
114
|
offlineHysteresisSeconds: node.offlineHysteresisSeconds,
|
|
115
|
+
repeatIntervalSeconds: node.repeatIntervalSeconds,
|
|
111
116
|
...(extra || {})
|
|
112
117
|
};
|
|
113
118
|
}
|
|
@@ -289,6 +294,33 @@ module.exports = function(RED) {
|
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
296
|
|
|
297
|
+
function resendCurrentPresence() {
|
|
298
|
+
// Re-emit the last debounced presence value without polling again.
|
|
299
|
+
// Skip until a value has actually been determined at least once.
|
|
300
|
+
if (node.currentPresence === null) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const clientId = resolveClientId(node.clientId);
|
|
304
|
+
if (!clientId) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
emitPresence(node.currentPresence, clientId, "repeat", "repeat");
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function stopRepeatTimer() {
|
|
311
|
+
if (node.repeatTimer) {
|
|
312
|
+
clearInterval(node.repeatTimer);
|
|
313
|
+
node.repeatTimer = null;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function startRepeatTimer() {
|
|
318
|
+
stopRepeatTimer();
|
|
319
|
+
if (node.repeatIntervalSeconds > 0) {
|
|
320
|
+
node.repeatTimer = setInterval(resendCurrentPresence, node.repeatIntervalSeconds * 1000);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
292
324
|
node.on("input", async function(_msg, send, done) {
|
|
293
325
|
send = send || function() {
|
|
294
326
|
node.send.apply(node, arguments);
|
|
@@ -344,6 +376,7 @@ module.exports = function(RED) {
|
|
|
344
376
|
node.server.addClient(node);
|
|
345
377
|
}
|
|
346
378
|
startObservation();
|
|
379
|
+
startRepeatTimer();
|
|
347
380
|
updateStatus();
|
|
348
381
|
requestPresenceSnapshot("startup").then((snapshot) => {
|
|
349
382
|
processPresenceSnapshot(snapshot);
|
|
@@ -356,6 +389,7 @@ module.exports = function(RED) {
|
|
|
356
389
|
|
|
357
390
|
node.on("close", function(done) {
|
|
358
391
|
try {
|
|
392
|
+
stopRepeatTimer();
|
|
359
393
|
stopObservation();
|
|
360
394
|
if (node.server && typeof node.server.removeClient === "function") {
|
|
361
395
|
node.server.removeClient(node);
|
package/package.json
CHANGED