node-red-contrib-unifi-ultimate 0.1.2 → 0.1.5

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.
Files changed (30) hide show
  1. package/README.md +115 -139
  2. package/nodes/icons/unifi-access-icon.svg +8 -0
  3. package/nodes/icons/unifi-network-icon.svg +12 -0
  4. package/nodes/icons/unifi-protect-icon.svg +3 -3
  5. package/nodes/readme-assets/unifi-access-door-access.jpg +0 -0
  6. package/nodes/readme-assets/unifi-network-switching.jpg +0 -0
  7. package/nodes/readme-assets/unifi-protect-camera.png +0 -0
  8. package/nodes/unifi-access-config.html +68 -9
  9. package/nodes/unifi-access-config.js +359 -25
  10. package/nodes/unifi-access-device.html +239 -41
  11. package/nodes/unifi-access-device.js +71 -47
  12. package/nodes/unifi-network-config.html +71 -11
  13. package/nodes/unifi-network-config.js +1173 -4
  14. package/nodes/unifi-network-control-poe.html +555 -48
  15. package/nodes/unifi-network-control-poe.js +258 -83
  16. package/nodes/unifi-network-device.html +303 -53
  17. package/nodes/unifi-network-device.js +21 -51
  18. package/nodes/unifi-network-presence.html +297 -38
  19. package/nodes/unifi-network-presence.js +11 -26
  20. package/nodes/unifi-protect-config.html +68 -9
  21. package/nodes/unifi-protect-device.html +237 -40
  22. package/nodes/unifi-protect-device.js +19 -25
  23. package/nodes/utils/unifi-access-device-registry.js +9 -17
  24. package/nodes/utils/unifi-network-device-registry.js +106 -27
  25. package/nodes/utils/unifi-protect-device-registry.js +15 -21
  26. package/package.json +15 -2
  27. package/scripts/discover-unifi-access-registry.js +24 -0
  28. package/scripts/discover-unifi-network-registry.js +26 -0
  29. package/scripts/discover-unifi-protect-registry.js +26 -0
  30. package/scripts/unifi-registry-discovery-common.js +1043 -0
@@ -1,11 +1,57 @@
1
1
  <style>
2
+ .unifi-ultimate-hero {
3
+ margin: 0 0 14px 0;
4
+ }
5
+
6
+ .unifi-ultimate-hero-panel {
7
+ padding: 14px 16px;
8
+ border: 1px solid #d9e7f5;
9
+ border-radius: 14px;
10
+ background: linear-gradient(135deg, #eef7ff 0%, #f8fbff 58%, #f7fafc 100%);
11
+ box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
12
+ color: #334155;
13
+ }
14
+
15
+ .unifi-ultimate-eyebrow {
16
+ margin-bottom: 4px;
17
+ color: #2563eb;
18
+ font-size: 11px;
19
+ font-weight: 700;
20
+ letter-spacing: 0.08em;
21
+ text-transform: uppercase;
22
+ }
23
+
24
+ .unifi-ultimate-hero-panel strong {
25
+ display: block;
26
+ color: #0f172a;
27
+ font-size: 15px;
28
+ line-height: 1.35;
29
+ }
30
+
31
+ .unifi-ultimate-hero-panel span {
32
+ display: block;
33
+ margin-top: 4px;
34
+ line-height: 1.45;
35
+ }
36
+
37
+ .unifi-ultimate-section-title {
38
+ margin: 14px 0 8px 150px;
39
+ color: #64748b;
40
+ font-size: 11px;
41
+ font-weight: 700;
42
+ letter-spacing: 0.08em;
43
+ text-transform: uppercase;
44
+ }
45
+
2
46
  .unifi-ultimate-card {
3
47
  margin-left: 150px;
4
- padding: 12px 14px;
5
- border-radius: 12px;
6
- background: #f5f7fa;
48
+ padding: 13px 15px;
49
+ border: 1px solid #e2e8f0;
50
+ border-radius: 14px;
51
+ background: #f8fafc;
7
52
  color: #334155;
8
53
  line-height: 1.45;
54
+ box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
9
55
  }
10
56
 
11
57
  .unifi-ultimate-card strong {
@@ -16,8 +62,8 @@
16
62
  }
17
63
 
18
64
  .unifi-ultimate-advanced {
19
- margin-top: 4px;
20
- padding-top: 4px;
65
+ margin-top: 14px;
66
+ padding-top: 10px;
21
67
  border-top: 1px solid #e5e7eb;
22
68
  }
23
69
 
@@ -38,7 +84,7 @@
38
84
  },
39
85
  inputs: 1,
40
86
  outputs: 2,
41
- icon: "unifi-protect-icon.svg",
87
+ icon: "unifi-access-icon.svg",
42
88
  paletteLabel: "ACCESS",
43
89
  outputLabels: ["state", "events"],
44
90
  label: function () {
@@ -101,7 +147,6 @@
101
147
  const $refresh = $("#node-input-refreshDevices");
102
148
  const $selectionSummary = $("#node-input-selectionSummary");
103
149
  const $selectionDetail = $("#node-input-selectionDetail");
104
- let lastAutoName = "";
105
150
  let capabilityConfig = parseCapabilityConfig(node.capabilityConfig);
106
151
  let capabilityListRequestId = 0;
107
152
  let capabilityOptionsRequestId = 0;
@@ -224,26 +269,179 @@
224
269
  if (!$select || $select.length === 0) {
225
270
  return;
226
271
  }
227
- // Searchable selects are disabled now, but this still removes any
228
- // cached helper input left by older editor versions.
229
272
  const selectId = String($select.attr("id") || "").trim();
230
- if (selectId) {
231
- const $searchInput = $("#" + selectId + "-search");
232
- if ($searchInput.length > 0) {
233
- try {
234
- if ($searchInput.data("ui-autocomplete")) {
235
- $searchInput.autocomplete("destroy");
236
- }
237
- } catch (error) {
238
- }
239
- $searchInput.remove();
240
- }
273
+ if (!selectId) {
274
+ return;
241
275
  }
242
276
 
277
+ const searchId = selectId + "-search";
243
278
  $select.off(".unifiSearchable");
244
279
  $select.removeData("unifi-searchable");
245
280
  $select.removeData("unifi-options-count");
246
281
  $select.show();
282
+
283
+ if ($select.is("select[multiple]")) {
284
+ return;
285
+ }
286
+
287
+ const $existingSearchInput = $("#" + searchId);
288
+ if ($existingSearchInput.length > 0) {
289
+ try {
290
+ if ($existingSearchInput.data("ui-autocomplete")) {
291
+ $existingSearchInput.autocomplete("destroy");
292
+ }
293
+ } catch (error) {
294
+ }
295
+ $existingSearchInput.off(".unifiSearchable");
296
+ $existingSearchInput.remove();
297
+ }
298
+
299
+ const $searchInput = $("<input>")
300
+ .attr("id", searchId)
301
+ .attr("type", "search")
302
+ .attr("autocomplete", "off")
303
+ .attr("placeholder", String(placeholder || "Search"))
304
+ .addClass("red-ui-input")
305
+ .css({
306
+ width: $select.css("width") || "100%",
307
+ marginBottom: "6px"
308
+ });
309
+ $select.before($searchInput);
310
+ $select.hide();
311
+
312
+ const options = $select.find("option").map(function () {
313
+ const $option = $(this);
314
+ const optionValue = String($option.val() || "").trim();
315
+ const optionText = String($option.text() || "").trim();
316
+ return {
317
+ value: optionValue,
318
+ text: optionText,
319
+ isPlaceholder: optionValue === "",
320
+ searchable: [
321
+ optionText,
322
+ String($option.attr("data-device-name") || "").trim(),
323
+ String($option.attr("data-client-name") || "").trim(),
324
+ optionValue
325
+ ].filter(Boolean).join(" ").toLowerCase()
326
+ };
327
+ }).get();
328
+
329
+ function findOptionByValue(value) {
330
+ return options.find(function (option) {
331
+ return String(option.value) === String(value || "").trim();
332
+ });
333
+ }
334
+
335
+ function syncInputFromSelect() {
336
+ const selectedValue = String($select.val() || "").trim();
337
+ const selected = findOptionByValue(selectedValue);
338
+ if (selected && !selected.isPlaceholder) {
339
+ $searchInput.val(selected.text);
340
+ } else {
341
+ $searchInput.val("");
342
+ }
343
+ }
344
+
345
+ function setSelectedValue(value, triggerChange) {
346
+ const selected = findOptionByValue(value);
347
+ if (selected) {
348
+ $select.val(selected.value);
349
+ } else {
350
+ $select.val("");
351
+ }
352
+ syncInputFromSelect();
353
+ if (triggerChange) {
354
+ $select.trigger("change");
355
+ }
356
+ }
357
+
358
+ let filterOnKeyUpOnly = false;
359
+ $searchInput.autocomplete({
360
+ minLength: 0,
361
+ source: function (request, response) {
362
+ const term = filterOnKeyUpOnly
363
+ ? String(request && request.term || "").trim().toLowerCase()
364
+ : "";
365
+ const items = options
366
+ .filter(function (option) {
367
+ if (option.isPlaceholder) {
368
+ return false;
369
+ }
370
+ if (!term) {
371
+ return true;
372
+ }
373
+ return option.searchable.indexOf(term) !== -1;
374
+ })
375
+ .map(function (option) {
376
+ return {
377
+ label: option.text,
378
+ value: option.text,
379
+ optionValue: option.value
380
+ };
381
+ });
382
+
383
+ if (items.length === 0) {
384
+ response([{
385
+ label: "No results",
386
+ value: "",
387
+ optionValue: "",
388
+ noSelection: true
389
+ }]);
390
+ return;
391
+ }
392
+
393
+ response(items);
394
+ },
395
+ select: function (event, ui) {
396
+ if (ui.item && ui.item.noSelection) {
397
+ event.preventDefault();
398
+ return false;
399
+ }
400
+ if (ui.item) {
401
+ setSelectedValue(ui.item.optionValue, true);
402
+ }
403
+ return true;
404
+ },
405
+ change: function (event, ui) {
406
+ if (ui.item) {
407
+ return;
408
+ }
409
+ const typed = String($searchInput.val() || "").trim().toLowerCase();
410
+ if (!typed) {
411
+ setSelectedValue("", true);
412
+ return;
413
+ }
414
+
415
+ const exactMatch = options.find(function (option) {
416
+ if (option.isPlaceholder) {
417
+ return false;
418
+ }
419
+ return option.text.toLowerCase() === typed || option.value.toLowerCase() === typed;
420
+ });
421
+
422
+ if (exactMatch) {
423
+ setSelectedValue(exactMatch.value, true);
424
+ } else {
425
+ syncInputFromSelect();
426
+ }
427
+ }
428
+ });
429
+
430
+ $searchInput.on("keyup.unifiSearchable", function () {
431
+ filterOnKeyUpOnly = true;
432
+ $(this).autocomplete("search", $(this).val());
433
+ });
434
+ $searchInput.on("mouseup.unifiSearchable", function () {
435
+ const $input = $(this);
436
+ filterOnKeyUpOnly = false;
437
+ setTimeout(function () {
438
+ $input.autocomplete("search", "");
439
+ }, 0);
440
+ });
441
+
442
+ syncInputFromSelect();
443
+ $select.data("unifi-searchable", true);
444
+ $select.data("unifi-options-count", options.length);
247
445
  }
248
446
 
249
447
  function syncCapabilityConfigFromInputs() {
@@ -365,15 +563,12 @@
365
563
 
366
564
  function syncNameFromSelection() {
367
565
  const selectedDeviceName = getSelectedDeviceName();
368
- const currentName = String($name.val() || "").trim();
369
- const shouldUpdate = currentName === "" || currentName === lastAutoName;
370
566
 
371
- if (!selectedDeviceName || !shouldUpdate) {
567
+ if (!selectedDeviceName) {
372
568
  return;
373
569
  }
374
570
 
375
571
  $name.val(selectedDeviceName);
376
- lastAutoName = selectedDeviceName;
377
572
  }
378
573
 
379
574
  function renderDeviceTypes(items) {
@@ -397,7 +592,6 @@
397
592
  $deviceType.val("");
398
593
  }
399
594
  });
400
- makeSelectSearchable($deviceType, "Search controls");
401
595
  refreshSelectionSummary();
402
596
  }
403
597
 
@@ -421,7 +615,6 @@
421
615
  $capability.val("observe");
422
616
  }
423
617
  });
424
- makeSelectSearchable($capability, "Search actions");
425
618
  refreshSelectionSummary();
426
619
  }
427
620
 
@@ -627,9 +820,6 @@
627
820
  }
628
821
 
629
822
  $capabilityConfigContainer.append($wrapper);
630
- if (field.type === "select") {
631
- makeSelectSearchable($input, "Search options");
632
- }
633
823
  });
634
824
 
635
825
  writeCapabilityConfig();
@@ -831,9 +1021,7 @@
831
1021
  }
832
1022
 
833
1023
  writeCapabilityConfig();
834
- makeSelectSearchable($deviceType, "Search controls");
835
1024
  makeSelectSearchable($deviceId, "Search devices");
836
- makeSelectSearchable($capability, "Search actions");
837
1025
 
838
1026
  $server.on("change", function () {
839
1027
  if (suspendChangeHandling || isInitializingEditor) {
@@ -879,10 +1067,19 @@
879
1067
  </script>
880
1068
 
881
1069
  <script type="text/html" data-template-name="unifi-access-device">
1070
+ <div class="form-row unifi-ultimate-hero">
1071
+ <div class="unifi-ultimate-hero-panel">
1072
+ <div class="unifi-ultimate-eyebrow">UniFi Access</div>
1073
+ <strong>Control doors and Access devices from a flow.</strong>
1074
+ <span>Choose a door or device, then select the action to run when a message arrives.</span>
1075
+ </div>
1076
+ </div>
1077
+ <div class="unifi-ultimate-section-title">Connection</div>
882
1078
  <div class="form-row">
883
1079
  <label for="node-input-server"><i class="fa fa-cog"></i> Connection</label>
884
1080
  <input type="text" id="node-input-server">
885
1081
  </div>
1082
+ <div class="unifi-ultimate-section-title">Target</div>
886
1083
  <div class="form-row">
887
1084
  <label for="node-input-deviceType"><i class="fa fa-cubes"></i> Control</label>
888
1085
  <select id="node-input-deviceType"></select>
@@ -894,6 +1091,7 @@
894
1091
  <i class="fa fa-refresh"></i>
895
1092
  </a>
896
1093
  </div>
1094
+ <div class="unifi-ultimate-section-title">Action</div>
897
1095
  <div class="form-row">
898
1096
  <label for="node-input-capability"><i class="fa fa-tasks"></i> Action</label>
899
1097
  <select id="node-input-capability"></select>
@@ -911,8 +1109,8 @@
911
1109
  </div>
912
1110
  <div id="node-row-advanced" class="unifi-ultimate-advanced">
913
1111
  <div class="form-row">
914
- <label for="node-input-name"><i class="fa fa-tag"></i> Label</label>
915
- <input type="text" id="node-input-name" placeholder="Optional custom label">
1112
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
1113
+ <input type="text" id="node-input-name" placeholder="Node name">
916
1114
  </div>
917
1115
  <div class="form-row">
918
1116
  <label for="node-input-timeout"><i class="fa fa-clock-o"></i> Timeout</label>
@@ -922,28 +1120,28 @@
922
1120
  </script>
923
1121
 
924
1122
  <script type="text/html" data-help-name="unifi-access-device">
925
- <p>Use this node to control a UniFi Access item or listen for its live events.</p>
1123
+ <p>Use this node to execute a configured UniFi Access action or listen for live Access events.</p>
926
1124
 
927
1125
  <h3>Configuration</h3>
928
1126
  <p><b>Connection</b> selects the shared UniFi Access config node.</p>
929
- <p><b>Control</b> chooses the Access category. <b>Device</b> chooses the specific door or Access device. <b>Action</b> only shows actions supported by that item.</p>
1127
+ <p><b>Control</b> chooses the Access category. <b>Device</b> chooses the specific door or Access device. Device selectors are searchable and open with the complete list before filtering.</p>
1128
+ <p><b>Action</b> only shows actions supported by the selected item.</p>
930
1129
  <p><b>Action options</b> appears only when the selected action needs extra input, such as a temporary lock rule or a room name for doorbell actions.</p>
931
1130
  <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>
932
1131
  <p><code>Receive Events</code> fetches the current state once and then listens to the official UniFi Access notifications WebSocket.</p>
933
1132
  <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>
934
- <p><code>Cancel Doorbell</code> uses a shared safe-cancel guard in the UniFi Access config node. A cancel request is sent only if an active ring is still tracked there, using a 3 minute tracking window.</p>
935
- <p><b>Label</b> is optional and only changes how the node is shown in the editor. <b>Timeout</b> controls the request timeout in milliseconds for direct API calls.</p>
1133
+ <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>
1134
+ <p><b>Name</b> is the node name shown in the editor and is updated automatically when you select a different item. <b>Timeout</b> controls the request timeout in milliseconds for direct API calls.</p>
936
1135
 
937
1136
  <h3>Input</h3>
938
1137
  <ul>
939
- <li><code>msg.deviceType</code>, <code>msg.deviceId</code>, and <code>msg.capability</code> for runtime overrides</li>
940
- <li><code>msg.capabilityConfig</code> for runtime overrides of the options selected in the editor</li>
941
- <li><code>msg.query</code>, <code>msg.headers</code>, and <code>msg.payload</code> for the HTTP request</li>
1138
+ <li>Any incoming message triggers the configured action.</li>
1139
+ <li>Input message properties are ignored by this node.</li>
942
1140
  </ul>
943
1141
 
944
1142
  <h3>Output</h3>
945
1143
  <ul>
946
- <li>Output 1: current state or primary capability response</li>
1144
+ <li>Output 1 emits a new message containing the current state or primary capability response.</li>
947
1145
  <li>Output 2: Access notification events related to the selected item</li>
948
1146
  <li><code>msg.unifiAccess</code>: standardized metadata for the device and selected capability</li>
949
1147
  <li>Safe-cancel skip: <code>msg.payload.skipped = true</code> when <code>Cancel Doorbell</code> is blocked because no active ring is currently tracked</li>
@@ -9,21 +9,19 @@ const {
9
9
  } = require("./utils/unifi-access-device-registry");
10
10
  const { extractAccessData } = require("./utils/unifi-access-utils");
11
11
 
12
- function resolveDeviceType(configuredDeviceType, msg) {
13
- return String(msg.deviceType || configuredDeviceType || "").trim();
12
+ function resolveDeviceType(configuredDeviceType) {
13
+ return String(configuredDeviceType || "").trim();
14
14
  }
15
15
 
16
- function resolveDeviceId(configuredDeviceId, msg) {
17
- return String(msg.deviceId || msg.resourceId || configuredDeviceId || "").trim();
16
+ function resolveDeviceId(configuredDeviceId) {
17
+ return String(configuredDeviceId || "").trim();
18
18
  }
19
19
 
20
- function resolveCapabilityId(configuredCapabilityId, msg) {
21
- return String(msg.capability || configuredCapabilityId || "observe").trim();
20
+ function resolveCapabilityId(configuredCapabilityId) {
21
+ return String(configuredCapabilityId || "observe").trim();
22
22
  }
23
23
 
24
24
  function parseCapabilityConfig(value) {
25
- // Access action options are stored as JSON by the editor, but runtime
26
- // overrides may pass an already parsed object.
27
25
  if (value && typeof value === "object" && !Array.isArray(value)) {
28
26
  return value;
29
27
  }
@@ -42,11 +40,7 @@ function parseCapabilityConfig(value) {
42
40
  }
43
41
  }
44
42
 
45
- function resolveCapabilityConfig(configuredCapabilityConfig, msg) {
46
- if (msg && msg.capabilityConfig && typeof msg.capabilityConfig === "object" && !Array.isArray(msg.capabilityConfig)) {
47
- return msg.capabilityConfig;
48
- }
49
-
43
+ function resolveCapabilityConfig(configuredCapabilityConfig) {
50
44
  return parseCapabilityConfig(configuredCapabilityConfig);
51
45
  }
52
46
 
@@ -116,17 +110,17 @@ module.exports = function(RED) {
116
110
  sendOutputs(send, stateMsg, null);
117
111
  }
118
112
 
119
- async function invokeCapability(msg, send) {
113
+ async function invokeCapability(send) {
120
114
  if (!node.server) {
121
115
  throw new Error("Unifi Access configuration is missing.");
122
116
  }
123
117
 
124
- // Resolve the final execution target by combining editor values with
125
- // any runtime overrides coming from the input message.
126
- const deviceType = resolveDeviceType(node.deviceType, msg);
127
- const deviceId = resolveDeviceId(node.deviceId, msg);
128
- const capabilityId = resolveCapabilityId(node.capability, msg);
129
- const capabilityConfig = resolveCapabilityConfig(node.capabilityConfig, msg);
118
+ // The incoming message is only a trigger. The node always uses the
119
+ // device, capability and options configured in the editor.
120
+ const deviceType = resolveDeviceType(node.deviceType);
121
+ const deviceId = resolveDeviceId(node.deviceId);
122
+ const capabilityId = resolveCapabilityId(node.capability);
123
+ const capabilityConfig = resolveCapabilityConfig(node.capabilityConfig);
130
124
  let selectedDevice = node.currentDevice;
131
125
 
132
126
  if (!getDeviceTypeDefinition(deviceType)) {
@@ -145,24 +139,49 @@ module.exports = function(RED) {
145
139
  throw new Error(`Unsupported capability '${capabilityId}' for device type '${deviceType}'.`);
146
140
  }
147
141
 
148
- if (capabilityId === "cancelDoorbell" && typeof node.server.hasAnyActiveDoorbell === "function" && !node.server.hasAnyActiveDoorbell()) {
149
- // UniFi Access does not provide a safe "cancel even if idle"
150
- // endpoint, so avoid firing blind cancel requests.
151
- const skippedMsg = RED.util.cloneMessage(msg);
152
- skippedMsg.payload = {
153
- skipped: true,
154
- reason: "No active doorbell ring is currently tracked by the UniFi Access configuration node."
142
+ if (capabilityId === "cancelDoorbell") {
143
+ const hasTrackedDoorbell = () => {
144
+ const hasByDevice = deviceId && typeof node.server.hasActiveDoorbell === "function"
145
+ ? node.server.hasActiveDoorbell(deviceId)
146
+ : false;
147
+ const hasByAny = typeof node.server.hasAnyActiveDoorbell === "function"
148
+ ? node.server.hasAnyActiveDoorbell()
149
+ : true;
150
+ // When the node is bound to one explicit device, only
151
+ // trust per-device tracking. Global fallback can cause
152
+ // false positives that re-enable the cancel toggle bug.
153
+ return deviceId ? hasByDevice : hasByAny;
155
154
  };
156
- skippedMsg.device = node.currentDevice;
157
- skippedMsg.unifiAccess = buildBaseMetadata(deviceType, deviceId, capabilityId, {
158
- source: "request",
159
- skipped: true,
160
- safeCancel: true
161
- });
162
155
 
163
- node.status({ fill: "yellow", shape: "ring", text: "no ring" });
164
- sendOutputs(send, skippedMsg, null);
165
- return;
156
+ // Prevent toggling: on some device types the cancel endpoint
157
+ // acts as a trigger when called with no active ring.
158
+ let hasActiveDoorbell = hasTrackedDoorbell();
159
+
160
+ if (!hasActiveDoorbell && typeof node.server.refreshDoorbellState === "function") {
161
+ // Some Access devices do not emit the expected doorbell
162
+ // websocket event family. Refresh from system logs once
163
+ // before deciding that no active ring is present.
164
+ await node.server.refreshDoorbellState({ lookbackSeconds: 45 });
165
+ hasActiveDoorbell = hasTrackedDoorbell();
166
+ }
167
+
168
+ if (!hasActiveDoorbell) {
169
+ const skippedMsg = {};
170
+ skippedMsg.payload = {
171
+ skipped: true,
172
+ reason: "No active doorbell ring is currently tracked by the UniFi Access configuration node."
173
+ };
174
+ skippedMsg.device = node.currentDevice;
175
+ skippedMsg.unifiAccess = buildBaseMetadata(deviceType, deviceId, capabilityId, {
176
+ source: "request",
177
+ skipped: true,
178
+ safeCancel: true
179
+ });
180
+
181
+ node.status({ fill: "yellow", shape: "ring", text: "no ring" });
182
+ sendOutputs(send, skippedMsg, null);
183
+ return;
184
+ }
166
185
  }
167
186
 
168
187
  if (capability.mode === "observe" || capability.mode === "fetch") {
@@ -178,7 +197,7 @@ module.exports = function(RED) {
178
197
  return;
179
198
  }
180
199
 
181
- const execution = composeCapabilityExecution(deviceType, capabilityId, capabilityConfig, msg, selectedDevice);
200
+ const execution = composeCapabilityExecution(deviceType, capabilityId, capabilityConfig, selectedDevice);
182
201
  const request = buildCapabilityRequest(deviceType, capabilityId, deviceId, selectedDevice);
183
202
 
184
203
  node.status({ fill: "blue", shape: "dot", text: `${capability.label}` });
@@ -197,24 +216,29 @@ module.exports = function(RED) {
197
216
  throw new Error(`UniFi Access request failed with status ${response.statusCode}`);
198
217
  }
199
218
 
219
+ const responseData = extractAccessData(response.payload);
220
+ if (responseData && typeof responseData === "object" && !Array.isArray(responseData)) {
221
+ node.currentDevice = responseData;
222
+ }
223
+
200
224
  if (capabilityId === "triggerDoorbell" && typeof node.server.markDoorbellTriggered === "function") {
201
225
  // Track the ring on the shared config node so a later cancel
202
226
  // request can be validated safely.
203
227
  node.server.markDoorbellTriggered(deviceId, {
228
+ requestId: String(
229
+ responseData && typeof responseData === "object"
230
+ ? (responseData.request_id || responseData.remote_call_request_id || "")
231
+ : ""
232
+ ).trim(),
204
233
  capabilityConfig
205
234
  });
206
235
  }
207
236
 
208
237
  if (capabilityId === "cancelDoorbell" && typeof node.server.markDoorbellCanceled === "function") {
209
- node.server.markDoorbellCanceled();
210
- }
211
-
212
- const responseData = extractAccessData(response.payload);
213
- if (responseData && typeof responseData === "object" && !Array.isArray(responseData)) {
214
- node.currentDevice = responseData;
238
+ node.server.markDoorbellCanceled(deviceId);
215
239
  }
216
240
 
217
- const stateMsg = RED.util.cloneMessage(msg);
241
+ const stateMsg = {};
218
242
  stateMsg.payload = responseData;
219
243
  stateMsg.statusCode = response.statusCode;
220
244
  stateMsg.headers = response.headers;
@@ -247,13 +271,13 @@ module.exports = function(RED) {
247
271
  });
248
272
  }
249
273
 
250
- node.on("input", async function(msg, send, done) {
274
+ node.on("input", async function(_msg, send, done) {
251
275
  send = send || function() {
252
276
  node.send.apply(node, arguments);
253
277
  };
254
278
 
255
279
  try {
256
- await invokeCapability(msg, send);
280
+ await invokeCapability(send);
257
281
  if (typeof done === "function") {
258
282
  done();
259
283
  }
@@ -262,7 +286,7 @@ module.exports = function(RED) {
262
286
  if (typeof done === "function") {
263
287
  done(error);
264
288
  } else {
265
- node.error(error, msg);
289
+ node.error(error);
266
290
  }
267
291
  }
268
292
  });