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.
@@ -14,7 +14,8 @@
14
14
  inputs: { value: 1 },
15
15
  capability: { value: "observe", required: true },
16
16
  capabilityConfig: { value: "{}" },
17
- timeout: { value: 15000, required: true, validate: RED.validators.number() }
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) {
@@ -564,6 +590,7 @@
564
590
  $capability.append(
565
591
  $("<option></option>")
566
592
  .val(item.id)
593
+ .attr("data-method", String(item.method || "").trim())
567
594
  .attr("data-opens-stream", item.opensEventStream === true ? "true" : "false")
568
595
  .text(item.label)
569
596
  );
@@ -1043,6 +1070,9 @@
1043
1070
  writeCapabilityConfig();
1044
1071
  refreshAfterCapabilityChange();
1045
1072
  });
1073
+ $autoEmit.on("change", function () {
1074
+ syncProgressiveRows();
1075
+ });
1046
1076
  $refresh.on("click", function (event) {
1047
1077
  event.preventDefault();
1048
1078
  refreshAfterServerChange();
@@ -1095,9 +1125,15 @@
1095
1125
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
1096
1126
  <input type="text" id="node-input-name" placeholder="Node name">
1097
1127
  </div>
1098
- <div class="form-row">
1099
- <label for="node-input-timeout"><i class="fa fa-clock-o"></i> Timeout</label>
1100
- <input type="text" id="node-input-timeout" placeholder="15000">
1128
+ <div class="form-row" id="node-row-autoEmit">
1129
+ <label for="node-input-autoEmit"><i class="fa fa-repeat"></i> Repeat</label>
1130
+ <input type="checkbox" id="node-input-autoEmit" style="display:inline-block; width:auto; vertical-align:top;">
1131
+ <span style="margin-left:8px;">Emit periodically</span>
1132
+ </div>
1133
+ <div class="form-row" id="node-row-autoEmitInterval">
1134
+ <label for="node-input-autoEmitInterval"><i class="fa fa-clock-o"></i> Every</label>
1135
+ <input type="number" id="node-input-autoEmitInterval" min="5" step="1" placeholder="60" style="width:120px;">
1136
+ <span style="margin-left:8px;">seconds</span>
1101
1137
  </div>
1102
1138
  </div>
1103
1139
  </script>
@@ -1114,8 +1150,10 @@
1114
1150
  <p>Additional fields appear only when the selected action needs extra input. For example, events, PTZ presets, live views, or discovered properties.</p>
1115
1151
  <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
1152
  <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 <code>true</code> or <code>false</code> and keeps the original context in <code>msg.details.raw</code>. Sensor observables include <code>Extreme Values</code>.</p>
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>
1153
+ <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>
1154
+ <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>
1155
+ <p>Request timeout is handled automatically by the node.</p>
1156
+ <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>
1119
1157
 
1120
1158
  <h3>Input</h3>
1121
1159
  <ul>
@@ -8,6 +8,7 @@ const {
8
8
  resolveObservableState,
9
9
  resolveObservableEventValue
10
10
  } = require("./utils/unifi-protect-device-registry");
11
+ const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
11
12
 
12
13
  function resolveDeviceType(configuredDeviceType) {
13
14
  return String(configuredDeviceType || "").trim();
@@ -44,6 +45,18 @@ function resolveCapabilityConfig(configuredCapabilityConfig) {
44
45
  return parseCapabilityConfig(configuredCapabilityConfig);
45
46
  }
46
47
 
48
+ function parseBoolean(value) {
49
+ return value === true || value === "true" || value === 1 || value === "1";
50
+ }
51
+
52
+ function parseIntervalSeconds(value, fallback) {
53
+ const numeric = Number(value);
54
+ if (!Number.isFinite(numeric) || numeric < 5) {
55
+ return fallback;
56
+ }
57
+ return Math.trunc(numeric);
58
+ }
59
+
47
60
  function buildNodeStatus(deviceType, payload) {
48
61
  const label = payload && payload.name ? payload.name : deviceType;
49
62
  const state = payload && payload.state ? payload.state : "ready";
@@ -154,10 +167,14 @@ module.exports = function(RED) {
154
167
  node.deviceId = config.deviceId || "";
155
168
  node.capability = config.capability || "observe";
156
169
  node.capabilityConfig = config.capabilityConfig || "{}";
170
+ node.autoEmit = parseBoolean(config.autoEmit);
171
+ node.autoEmitIntervalSeconds = parseIntervalSeconds(config.autoEmitInterval, 60);
172
+ node.autoEmitTimer = null;
173
+ node.autoEmitInFlight = false;
157
174
  node.deviceName = resolveDeviceName(config.deviceName);
158
- node.timeout = Number(config.timeout) > 0 ? Number(config.timeout) : 15000;
175
+ node.timeout = DEFAULT_REQUEST_TIMEOUT_MS;
159
176
  node.currentDevice = null;
160
- node.currentObservableValue = false;
177
+ node.currentObservableValue = undefined;
161
178
  node.isObserving = false;
162
179
 
163
180
  function setNodeStatus(status) {
@@ -223,9 +240,9 @@ module.exports = function(RED) {
223
240
  const observable = resolveConfiguredObservable(capabilityConfig);
224
241
  if (observable) {
225
242
  // Observables let the node collapse complex Protect payloads into
226
- // a stable boolean while preserving the original context in details.raw.
243
+ // a stable typed value while preserving the original context in details.raw.
227
244
  const observableValue = resolveObservableState(deviceType, payload, observable, node.currentObservableValue);
228
- node.currentObservableValue = Boolean(observableValue);
245
+ node.currentObservableValue = observableValue;
229
246
 
230
247
  const outputMsg = {
231
248
  payload: node.currentObservableValue,
@@ -273,7 +290,7 @@ module.exports = function(RED) {
273
290
  sendOutputs(send, stateMsg, null);
274
291
  }
275
292
 
276
- async function invokeCapability(send) {
293
+ async function invokeCapability(send, triggerSource) {
277
294
  if (!node.server) {
278
295
  throw new Error("Unifi Protect configuration is missing.");
279
296
  }
@@ -303,7 +320,7 @@ module.exports = function(RED) {
303
320
 
304
321
  if (capability.mode === "observe") {
305
322
  // Manual input on an observe node acts like a forced refresh.
306
- await fetchDeviceState(deviceType, deviceId, capabilityConfig, send, "manual-refresh");
323
+ await fetchDeviceState(deviceType, deviceId, capabilityConfig, send, triggerSource || "manual-refresh");
307
324
  return;
308
325
  }
309
326
 
@@ -369,6 +386,16 @@ module.exports = function(RED) {
369
386
  return resolveCapabilityId(node.capability) === "observe";
370
387
  }
371
388
 
389
+ function configuredCapabilitySupportsAutoEmit() {
390
+ const capability = resolveConfiguredCapabilityDefinition();
391
+ if (!capability || capability.opensEventStream === true) {
392
+ return false;
393
+ }
394
+
395
+ const method = String(capability.method || "").trim().toUpperCase();
396
+ return !method || method === "GET";
397
+ }
398
+
372
399
  function shouldObserveConfiguredDevice() {
373
400
  return node.server && configuredCapabilityOpensEventStream() && node.deviceType && node.deviceId;
374
401
  }
@@ -392,13 +419,57 @@ module.exports = function(RED) {
392
419
  });
393
420
  }
394
421
 
422
+ function stopAutoEmitTimer() {
423
+ if (node.autoEmitTimer) {
424
+ clearInterval(node.autoEmitTimer);
425
+ node.autoEmitTimer = null;
426
+ }
427
+ node.autoEmitInFlight = false;
428
+ }
429
+
430
+ function shouldStartAutoEmitTimer() {
431
+ return Boolean(
432
+ node.server
433
+ && node.autoEmit
434
+ && node.deviceType
435
+ && node.deviceId
436
+ && configuredCapabilitySupportsAutoEmit()
437
+ );
438
+ }
439
+
440
+ function runAutoEmit() {
441
+ if (node.autoEmitInFlight || !shouldStartAutoEmitTimer()) {
442
+ return;
443
+ }
444
+
445
+ node.autoEmitInFlight = true;
446
+ invokeCapability(node.send.bind(node), "interval")
447
+ .catch((error) => {
448
+ setNodeStatus({ fill: "red", shape: "ring", text: "auto error" });
449
+ node.error(error);
450
+ })
451
+ .finally(() => {
452
+ node.autoEmitInFlight = false;
453
+ });
454
+ }
455
+
456
+ function startAutoEmitTimer() {
457
+ stopAutoEmitTimer();
458
+ if (!shouldStartAutoEmitTimer()) {
459
+ return;
460
+ }
461
+
462
+ node.autoEmitTimer = setInterval(runAutoEmit, node.autoEmitIntervalSeconds * 1000);
463
+ setNodeStatus({ fill: "grey", shape: "ring", text: `every ${node.autoEmitIntervalSeconds}s` });
464
+ }
465
+
395
466
  node.on("input", async function(_msg, send, done) {
396
467
  send = send || function() {
397
468
  node.send.apply(node, arguments);
398
469
  };
399
470
 
400
471
  try {
401
- await invokeCapability(send);
472
+ await invokeCapability(send, "manual-refresh");
402
473
  if (typeof done === "function") {
403
474
  done();
404
475
  }
@@ -454,11 +525,11 @@ module.exports = function(RED) {
454
525
  const observableScopeId = resolveConfiguredObservableScope(capabilityConfig);
455
526
  if (observable) {
456
527
  // When the user selected an observable, events can update the
457
- // boolean state output directly instead of only the event port.
528
+ // state output directly instead of only the event payload.
458
529
  const observation = resolveObservableEventValue(node.deviceType, item, observable, observableScopeId);
459
530
  if (observation.matched) {
460
531
  const resolvedDeviceName = resolveOutputDeviceName(node.currentDevice);
461
- node.currentObservableValue = Boolean(observation.value);
532
+ node.currentObservableValue = observation.value;
462
533
  setNodeStatus({ fill: "blue", shape: "ring", text: `${item.type || "event"}` });
463
534
  const stateMsg = {
464
535
  payload: node.currentObservableValue,
@@ -543,10 +614,12 @@ module.exports = function(RED) {
543
614
  setNodeStatus({ fill: "yellow", shape: "ring", text: "select device" });
544
615
  } else {
545
616
  startObservation();
617
+ startAutoEmitTimer();
546
618
  }
547
619
 
548
620
  node.on("close", function(done) {
549
621
  try {
622
+ stopAutoEmitTimer();
550
623
  if (node.server && typeof node.server.removeClient === "function") {
551
624
  node.server.removeClient(node);
552
625
  }
@@ -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
- { value: "all", label: "All" }
278
- ],
279
- defaultValue: "all",
280
- helpText: "Emit all events for the selected Access device or door."
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
  };
@@ -93,9 +93,74 @@ const TYPE_CAPABILITIES = {
93
93
  method: "GET",
94
94
  path: "/v1/sites/{siteId}/clients",
95
95
  mode: "request"
96
+ },
97
+ {
98
+ id: "countOnlineClients",
99
+ label: "Count Online Clients",
100
+ description: "Count currently online clients for the selected site.",
101
+ mode: "custom"
102
+ },
103
+ {
104
+ id: "createGuestVoucher",
105
+ label: "Create Guest Voucher",
106
+ description: "Create one or more simple Hotspot guest vouchers.",
107
+ method: "POST",
108
+ path: "/v1/sites/{siteId}/hotspot/vouchers",
109
+ mode: "custom",
110
+ editor: {
111
+ fields: [
112
+ {
113
+ id: "name",
114
+ label: "Name",
115
+ type: "text",
116
+ placeholder: "Guest Voucher",
117
+ defaultValue: "Guest Voucher"
118
+ },
119
+ {
120
+ id: "timeLimitMinutes",
121
+ label: "Duration (minutes)",
122
+ type: "number",
123
+ placeholder: "1440",
124
+ defaultValue: 1440
125
+ },
126
+ {
127
+ id: "count",
128
+ label: "How Many",
129
+ type: "number",
130
+ placeholder: "1",
131
+ defaultValue: 1
132
+ }
133
+ ]
134
+ },
135
+ requestComposer: ({ capabilityConfig }) => {
136
+ const normalizedName = String(capabilityConfig && capabilityConfig.name || "Guest Voucher").trim() || "Guest Voucher";
137
+ const timeLimitMinutes = resolveIntegerValue(undefined, capabilityConfig && capabilityConfig.timeLimitMinutes, 1) || 1440;
138
+ const count = resolveIntegerValue(undefined, capabilityConfig && capabilityConfig.count, 1) || 1;
139
+
140
+ if (timeLimitMinutes > 1000000) {
141
+ throw new Error("Guest voucher duration must be between 1 and 1000000 minutes.");
142
+ }
143
+ if (count > 1000) {
144
+ throw new Error("Guest voucher count must be between 1 and 1000.");
145
+ }
146
+
147
+ return {
148
+ payload: {
149
+ name: normalizedName,
150
+ timeLimitMinutes,
151
+ count
152
+ }
153
+ };
154
+ }
96
155
  }
97
156
  ],
98
157
  device: [
158
+ {
159
+ id: "readSwitchTemperatures",
160
+ label: "Read Temperatures",
161
+ description: "Fetch temperature readings exposed by the selected UniFi switch or device. Some models/controllers do not expose temperature data.",
162
+ mode: "custom"
163
+ },
99
164
  {
100
165
  id: "getLatestStatistics",
101
166
  label: "Read Latest Statistics",
@@ -104,6 +169,30 @@ const TYPE_CAPABILITIES = {
104
169
  path: "/v1/sites/{siteId}/devices/{deviceId}/statistics/latest",
105
170
  mode: "request"
106
171
  },
172
+ {
173
+ id: "readDeviceCpu",
174
+ label: "Read CPU",
175
+ description: "Read the selected UniFi device CPU usage percentage.",
176
+ method: "GET",
177
+ path: "/v1/sites/{siteId}/devices/{deviceId}/statistics/latest",
178
+ mode: "custom"
179
+ },
180
+ {
181
+ id: "readDeviceMemory",
182
+ label: "Read Memory",
183
+ description: "Read the selected UniFi device memory usage percentage.",
184
+ method: "GET",
185
+ path: "/v1/sites/{siteId}/devices/{deviceId}/statistics/latest",
186
+ mode: "custom"
187
+ },
188
+ {
189
+ id: "readDeviceUptime",
190
+ label: "Read Uptime",
191
+ description: "Read the selected UniFi device uptime in seconds.",
192
+ method: "GET",
193
+ path: "/v1/sites/{siteId}/devices/{deviceId}/statistics/latest",
194
+ mode: "custom"
195
+ },
107
196
  {
108
197
  id: "restartDevice",
109
198
  label: "Restart Device",
@@ -164,6 +253,12 @@ const TYPE_CAPABILITIES = {
164
253
  }
165
254
  ],
166
255
  client: [
256
+ {
257
+ id: "isClientOnline",
258
+ label: "Is Client Online",
259
+ description: "Return true when the selected client is online.",
260
+ mode: "custom"
261
+ },
167
262
  {
168
263
  id: "authorizeGuestAccess",
169
264
  label: "Authorize Guest Access",