node-red-contrib-unifi-ultimate 1.0.7 → 1.0.8

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.
@@ -10,39 +10,37 @@
10
10
  server: { value: "", type: "unifi-network-config", required: true },
11
11
  selectionMode: { value: "switchPort", required: true },
12
12
  clientLookupId: { value: "" },
13
- deviceId: { value: "", required: true },
13
+ deviceId: { value: "" },
14
14
  deviceName: { value: "" },
15
- portIdx: { value: 1, required: true, validate: RED.validators.number() },
16
- action: { value: "msgPayload", required: true }
15
+ portIdx: { value: 1 },
16
+ controlType: { value: "poe", required: true },
17
+ action: { value: "msgPayload", required: true },
18
+ targets: {
19
+ value: "[]",
20
+ validate: function (value) {
21
+ try {
22
+ const parsed = JSON.parse(value || "[]");
23
+ return Array.isArray(parsed) && parsed.length > 0;
24
+ } catch (error) {
25
+ return false;
26
+ }
27
+ }
28
+ }
17
29
  },
18
30
  inputs: 1,
19
31
  outputs: 2,
20
32
  icon: "unifi-u-logo-light-network.svg",
21
- paletteLabel: "Control POE",
33
+ paletteLabel: "Clients Control",
22
34
  outputLabels: ["result", "error"],
23
35
  label: function () {
24
- return this.name || "Control POE";
36
+ return this.name || "Clients Control";
25
37
  },
26
38
  oneditsave: function () {
39
+ // The clients list is persisted through the hidden #node-input-targets
40
+ // field. Here we only keep the dynamic input-pin visibility in sync:
41
+ // the streaming power-observation action accepts no input trigger.
27
42
  const actionValue = String($("#node-input-action").val() || "").trim().toLowerCase();
28
43
  const opensObservation = ["emitpowerconsumption"].includes(actionValue);
29
- const selectionMode = String($("#node-input-selectionMode").val() || "switchPort").trim();
30
-
31
- if (selectionMode === "client") {
32
- const $selectedClient = $("#node-input-clientLookupId option:selected");
33
- const derivedDeviceId = String($selectedClient.attr("data-attached-device-id") || "").trim();
34
- const derivedPortIdx = String($selectedClient.attr("data-attached-port-idx") || "").trim();
35
- if (derivedDeviceId && derivedPortIdx !== "") {
36
- $("#node-input-deviceId").val(derivedDeviceId);
37
- $("#node-input-portIdx").val(derivedPortIdx);
38
- this.deviceId = derivedDeviceId;
39
- const numericPortIdx = Number(derivedPortIdx);
40
- this.portIdx = Number.isFinite(numericPortIdx)
41
- ? Math.trunc(numericPortIdx)
42
- : derivedPortIdx;
43
- }
44
- }
45
-
46
44
  this.inputs = opensObservation ? 0 : 1;
47
45
  },
48
46
  oneditprepare: function () {
@@ -54,6 +52,8 @@
54
52
  const $deviceId = $("#node-input-deviceId");
55
53
  const $clientLookupId = $("#node-input-clientLookupId");
56
54
  const $portIdx = $("#node-input-portIdx");
55
+ const $controlType = $("#node-input-controlType");
56
+ const $controlTypeRow = $("#node-row-controlType");
57
57
  const $action = $("#node-input-action");
58
58
  const $refreshDevices = $("#node-input-refreshDevices");
59
59
  const $refreshClients = $("#node-input-refreshClients");
@@ -64,6 +64,11 @@
64
64
  const $actionRow = $action.closest(".form-row");
65
65
  const $warningRow = $(".unifi-ultimate-warning").closest(".form-row");
66
66
  const $advancedRow = $("#node-row-advanced");
67
+ const $addTarget = $("#node-input-addTarget");
68
+ const $addRow = $("#node-row-addTarget");
69
+ const $pickerBox = $("#node-row-picker");
70
+ const $targetsRow = $("#node-row-targets");
71
+ let targetList = [];
67
72
  let suspendChangeHandling = false;
68
73
  let isInitializingEditor = true;
69
74
  let clientTargetsPopulated = false;
@@ -83,16 +88,190 @@
83
88
  const hasSwitch = hasSelection($deviceId);
84
89
  const hasPort = hasSelection($portIdx);
85
90
  const hasClient = hasSelection($clientLookupId);
86
- const hasTarget = mode === "client" ? hasClient : (hasSwitch && hasPort);
91
+ // A "current selection" is what the Add button would append; the
92
+ // action and downstream rows depend on the accumulated list.
93
+ const hasCurrentSelection = mode === "client" ? hasClient : (hasSwitch && hasPort);
94
+ const hasList = targetList.length > 0;
87
95
  const hasAction = hasSelection($action);
88
96
 
97
+ $pickerBox.toggle(hasServer);
89
98
  $selectionModeRow.toggle(hasServer);
90
99
  $rowSwitch.toggle(hasServer && mode === "switchPort");
91
100
  $rowPort.toggle(hasServer && mode === "switchPort" && hasSwitch);
92
101
  $rowClient.toggle(hasServer && mode === "client");
93
- $actionRow.toggle(hasServer && hasTarget);
94
- $warningRow.toggle(hasServer && hasTarget && hasAction);
95
- $advancedRow.toggle(hasServer && hasTarget && hasAction);
102
+ $addRow.toggle(hasServer && hasCurrentSelection);
103
+ $targetsRow.toggle(hasServer);
104
+ $controlTypeRow.toggle(hasServer && hasList);
105
+ $actionRow.toggle(hasServer && hasList);
106
+ $warningRow.toggle(hasServer && hasList && hasAction);
107
+ $advancedRow.toggle(hasServer && hasList && hasAction);
108
+ }
109
+
110
+ function targetKey(target) {
111
+ return String(target.deviceId) + "|" + String(target.portIdx);
112
+ }
113
+
114
+ function persistTargets() {
115
+ $("#node-input-targets").val(JSON.stringify(targetList));
116
+ }
117
+
118
+ function getCurrentSelectionTarget() {
119
+ if (getSelectionMode() === "client") {
120
+ const $selected = $clientLookupId.find("option:selected");
121
+ const deviceId = String($selected.attr("data-attached-device-id") || "").trim();
122
+ const portRaw = String($selected.attr("data-attached-port-idx") || "").trim();
123
+ const clientId = String($clientLookupId.val() || "").trim();
124
+ const portIdx = Number(portRaw);
125
+ if (!deviceId || portRaw === "" || !Number.isFinite(portIdx) || !clientId) {
126
+ return null;
127
+ }
128
+ const clientName = String($selected.attr("data-client-name") || "").trim();
129
+ const switchName = String($selected.attr("data-attached-device-name") || "Switch").trim();
130
+ return {
131
+ deviceId: deviceId,
132
+ portIdx: portIdx,
133
+ clientId: clientId,
134
+ name: (clientName || clientId) + " → " + switchName + " p" + portIdx
135
+ };
136
+ }
137
+
138
+ const deviceId = String($deviceId.val() || "").trim();
139
+ const portRaw = String($portIdx.val() || "").trim();
140
+ const portIdx = Number(portRaw);
141
+ if (!deviceId || deviceId === "_ADD_" || portRaw === "" || !Number.isFinite(portIdx)) {
142
+ return null;
143
+ }
144
+ const deviceName = getSelectedDeviceName() || deviceId;
145
+ return {
146
+ deviceId: deviceId,
147
+ portIdx: portIdx,
148
+ clientId: "",
149
+ name: deviceName + " p" + portIdx
150
+ };
151
+ }
152
+
153
+ function renderTargetList() {
154
+ const $list = $("#unifi-poe-target-list");
155
+ $list.empty();
156
+
157
+ if (targetList.length === 0) {
158
+ $list.append(
159
+ $("<div class='unifi-poe-target-empty'></div>")
160
+ .text("No clients added yet. Pick a target above and click \"Add to list\".")
161
+ );
162
+ } else {
163
+ targetList.forEach(function (target, index) {
164
+ const $row = $("<div class='unifi-poe-target-row'></div>");
165
+ $row.append(
166
+ $("<span class='unifi-poe-target-name'></span>")
167
+ .text(target.name || (target.deviceId + " p" + target.portIdx))
168
+ );
169
+ $row.append($("<span class='unifi-poe-target-meta'></span>").text("p" + target.portIdx));
170
+ const $remove = $("<a href='#' class='unifi-poe-target-remove' title='Remove'><i class='fa fa-times'></i></a>");
171
+ $remove.on("click", function (event) {
172
+ event.preventDefault();
173
+ targetList.splice(index, 1);
174
+ renderTargetList();
175
+ syncPowerActionAvailability();
176
+ refreshSummary();
177
+ });
178
+ $row.append($remove);
179
+ $list.append($row);
180
+ });
181
+ }
182
+
183
+ $("#unifi-poe-target-count").text(targetList.length + " selected");
184
+ persistTargets();
185
+ }
186
+
187
+ function addCurrentTarget() {
188
+ const target = getCurrentSelectionTarget();
189
+ if (!target) {
190
+ RED.notify("Select a switch port or a client first.", "warning");
191
+ return;
192
+ }
193
+ if (targetList.some(function (existing) { return targetKey(existing) === targetKey(target); })) {
194
+ RED.notify("That port is already in the list.", "info");
195
+ return;
196
+ }
197
+
198
+ targetList.push(target);
199
+ renderTargetList();
200
+ syncPowerActionAvailability();
201
+ refreshSummary();
202
+ }
203
+
204
+ function syncPowerActionAvailability() {
205
+ // The streaming "Emit Power Consumption" action only makes sense
206
+ // for a single target, so it is disabled for lists of 0 or 2+.
207
+ const $option = $action.find("option[value='emitPowerConsumption']");
208
+ const allowed = targetList.length === 1;
209
+ $option.prop("disabled", !allowed);
210
+ if (!allowed && getSelectedActionValue() === "emitpowerconsumption") {
211
+ $action.val("msgPayload");
212
+ refreshActionUi();
213
+ }
214
+ }
215
+
216
+ function initTargetList() {
217
+ let stored = [];
218
+ try {
219
+ if (Array.isArray(node.targets)) {
220
+ stored = node.targets;
221
+ } else if (typeof node.targets === "string" && node.targets.trim()) {
222
+ stored = JSON.parse(node.targets);
223
+ }
224
+ } catch (error) {
225
+ stored = [];
226
+ }
227
+ if (!Array.isArray(stored)) {
228
+ stored = [];
229
+ }
230
+
231
+ const seen = {};
232
+ targetList = stored.map(function (entry) {
233
+ if (!entry || typeof entry !== "object") {
234
+ return null;
235
+ }
236
+ const deviceId = String(entry.deviceId || "").trim();
237
+ const portIdx = Number(entry.portIdx);
238
+ if (!deviceId || !Number.isFinite(portIdx)) {
239
+ return null;
240
+ }
241
+ return {
242
+ deviceId: deviceId,
243
+ portIdx: portIdx,
244
+ clientId: String(entry.clientId || "").trim(),
245
+ name: String(entry.name || "").trim()
246
+ };
247
+ }).filter(function (entry) {
248
+ if (!entry) {
249
+ return false;
250
+ }
251
+ const key = targetKey(entry);
252
+ if (seen[key]) {
253
+ return false;
254
+ }
255
+ seen[key] = true;
256
+ return true;
257
+ });
258
+
259
+ // Migrate a legacy single-target node into a one-entry list.
260
+ if (targetList.length === 0) {
261
+ const legacyDeviceId = String(node.deviceId || "").trim();
262
+ const legacyPortRaw = String(node.portIdx === undefined || node.portIdx === null ? "" : node.portIdx).trim();
263
+ const legacyPort = Number(legacyPortRaw);
264
+ if (legacyDeviceId && legacyPortRaw !== "" && Number.isFinite(legacyPort)) {
265
+ targetList.push({
266
+ deviceId: legacyDeviceId,
267
+ portIdx: legacyPort,
268
+ clientId: String(node.clientLookupId || "").trim(),
269
+ name: String(node.deviceName || "").trim() || (legacyDeviceId + " p" + legacyPort)
270
+ });
271
+ }
272
+ }
273
+
274
+ persistTargets();
96
275
  }
97
276
 
98
277
  function setClientWaitOverlay(visible, message) {
@@ -127,6 +306,38 @@
127
306
  return String($action.val() || node.action || "msgPayload").trim().toLowerCase();
128
307
  }
129
308
 
309
+ function getControlType() {
310
+ return String($controlType.val() || node.controlType || "poe").trim() === "port" ? "port" : "poe";
311
+ }
312
+
313
+ function renderActionOptions() {
314
+ // The action list depends on the chosen control domain. PoE keeps
315
+ // its full set; port mode only enables/disables the switch port.
316
+ const controlType = getControlType();
317
+ const current = String($action.val() || node.action || "msgPayload").trim();
318
+ const options = controlType === "port"
319
+ ? [
320
+ ["msgPayload", "Port controlled by msg.payload"],
321
+ ["enable", "Enable port"],
322
+ ["disable", "Disable port"]
323
+ ]
324
+ : [
325
+ ["msgPayload", "POE controlled by msg.payload"],
326
+ ["enable", "Enable PoE"],
327
+ ["disable", "Disable PoE"],
328
+ ["cycle", "Power Cycle"],
329
+ ["emitPowerConsumption", "Emit Power Consumption"]
330
+ ];
331
+
332
+ $action.empty();
333
+ options.forEach(function (option) {
334
+ $action.append($("<option></option>").val(option[0]).text(option[1]));
335
+ });
336
+
337
+ const hasCurrent = options.some(function (option) { return option[0] === current; });
338
+ $action.val(hasCurrent ? current : "msgPayload");
339
+ }
340
+
130
341
  function selectedActionObservesPower() {
131
342
  return ["emitpowerconsumption"].includes(getSelectedActionValue());
132
343
  }
@@ -675,42 +886,25 @@
675
886
  refreshSummary();
676
887
  }
677
888
 
678
- function renderSavedClientSelection() {
679
- const savedClientId = String(node.clientLookupId || "").trim();
680
- const savedClientName = String(node.deviceName || "").trim();
681
- const savedDeviceId = String(node.deviceId || "").trim();
682
- const savedPortIdx = String(node.portIdx || "").trim();
889
+ function renderEmptyClientSelection() {
890
+ // Open with an empty Client picker: restoring a saved client would
891
+ // trigger a pointless switch/port resolution on every open. The
892
+ // configured targets already live in the list, and the picker is
893
+ // only used to add new ones.
683
894
  suspendChangeHandling = true;
684
895
  try {
685
896
  $clientLookupId.empty();
686
897
  $clientLookupId.append($("<option></option>").val("").text("Choose a client target"));
687
- if (savedClientId) {
688
- const label = savedClientName || savedClientId;
689
- const $savedOption = $("<option></option>")
690
- .val(savedClientId)
691
- .text(label)
692
- .attr("data-client-name", label);
693
- if (savedDeviceId) {
694
- $savedOption.attr("data-attached-device-id", savedDeviceId);
695
- }
696
- if (savedPortIdx !== "") {
697
- $savedOption.attr("data-attached-port-idx", savedPortIdx);
698
- }
699
- $clientLookupId.append($savedOption);
700
- $clientLookupId.val(savedClientId);
701
- } else {
702
- $clientLookupId.val("");
703
- }
898
+ $clientLookupId.val("");
704
899
  } finally {
705
900
  suspendChangeHandling = false;
706
901
  }
707
902
 
708
903
  clientTargetsLoading = false;
709
- clientTargetsPopulated = savedClientId !== "";
904
+ clientTargetsPopulated = false;
710
905
  makeSelectSearchable($clientLookupId, "Search clients");
711
906
  bindLazyClientLookupLoad();
712
907
  updateDerivedTargetFieldsState();
713
- rememberSelectedTargetName();
714
908
  refreshSummary();
715
909
  }
716
910
 
@@ -842,58 +1036,6 @@
842
1036
  return clientsRequestPromise;
843
1037
  }
844
1038
 
845
- function applySelectedClientTarget(options) {
846
- const settings = options && typeof options === "object" ? options : {};
847
- const shouldSyncName = settings.syncName === true;
848
- const $selected = $clientLookupId.find("option:selected");
849
- const targetDeviceId = String($selected.attr("data-attached-device-id") || "").trim();
850
- const targetPortIdx = String($selected.attr("data-attached-port-idx") || "").trim();
851
- if (!targetDeviceId || targetPortIdx === "") {
852
- rememberSelectedTargetName();
853
- if (shouldSyncName) {
854
- syncNameFromSelection();
855
- }
856
- refreshSummary();
857
- return Promise.resolve();
858
- }
859
-
860
- const ensureDevicePresent = hasOptionValue($deviceId, targetDeviceId)
861
- ? Promise.resolve()
862
- : loadDevices();
863
-
864
- return ensureDevicePresent.then(function () {
865
- if (!hasOptionValue($deviceId, targetDeviceId)) {
866
- refreshSummary();
867
- return;
868
- }
869
-
870
- suspendChangeHandling = true;
871
- try {
872
- $deviceId.val(targetDeviceId);
873
- } finally {
874
- suspendChangeHandling = false;
875
- }
876
- makeSelectSearchable($deviceId, "Search switches");
877
-
878
- return loadPorts().then(function () {
879
- if (hasOptionValue($portIdx, targetPortIdx)) {
880
- suspendChangeHandling = true;
881
- try {
882
- $portIdx.val(targetPortIdx);
883
- } finally {
884
- suspendChangeHandling = false;
885
- }
886
- }
887
-
888
- rememberSelectedTargetName();
889
- if (shouldSyncName) {
890
- syncNameFromSelection();
891
- }
892
- refreshSummary();
893
- });
894
- });
895
- }
896
-
897
1039
  function loadEditorData(options) {
898
1040
  const settings = options && typeof options === "object" ? options : {};
899
1041
  const shouldLoadClients = settings.loadClients === true;
@@ -905,10 +1047,6 @@
905
1047
  force: settings.forceClients === true,
906
1048
  showLoading: settings.showClientsLoading !== false
907
1049
  });
908
- }).then(function () {
909
- if (getSelectionMode() === "client") {
910
- return applySelectedClientTarget();
911
- }
912
1050
  }).finally(function () {
913
1051
  refreshSummary();
914
1052
  });
@@ -953,6 +1091,12 @@
953
1091
  });
954
1092
 
955
1093
  $portIdx.on("change", refreshSummary);
1094
+ $controlType.on("change", function () {
1095
+ renderActionOptions();
1096
+ syncPowerActionAvailability();
1097
+ refreshActionUi();
1098
+ refreshSummary();
1099
+ });
956
1100
  $action.on("change", function () {
957
1101
  refreshActionUi();
958
1102
  refreshSummary();
@@ -964,10 +1108,11 @@
964
1108
  refreshSelectionModeUi();
965
1109
  rememberSelectedTargetName();
966
1110
  if (getSelectionMode() === "client") {
1111
+ // Only load the client dropdown so the user can pick one. The
1112
+ // switch/port for the chosen client lives on the option's
1113
+ // data-attached-* attributes, so there is nothing to resolve.
967
1114
  withClientWait("Loading client targets...", function () {
968
- return loadClients({ showLoading: false }).then(function () {
969
- return applySelectedClientTarget();
970
- });
1115
+ return loadClients({ showLoading: false });
971
1116
  });
972
1117
  } else {
973
1118
  refreshSummary();
@@ -980,42 +1125,42 @@
980
1125
  rememberSelectedTargetName();
981
1126
  const isUserSelection = $clientLookupId.data("unifi-user-selection") === true;
982
1127
  $clientLookupId.removeData("unifi-user-selection");
983
- if (getSelectionMode() === "client") {
984
- withClientWait("Resolving client switch and port...", function () {
985
- return applySelectedClientTarget({ syncName: isUserSelection });
986
- });
987
- } else {
988
- refreshSummary();
1128
+ if (isUserSelection) {
1129
+ syncNameFromSelection();
989
1130
  }
1131
+ refreshSummary();
990
1132
  });
991
1133
 
992
1134
  $refreshDevices.on("click", function (event) {
993
1135
  event.preventDefault();
994
- loadDevices().then(function () {
995
- if (getSelectionMode() === "client") {
996
- return applySelectedClientTarget();
997
- }
998
- });
1136
+ loadDevices();
999
1137
  });
1000
1138
  $refreshClients.on("click", function (event) {
1001
1139
  event.preventDefault();
1002
1140
  withClientWait("Loading client targets...", function () {
1003
- return loadClients({ force: true }).then(function () {
1004
- if (getSelectionMode() === "client") {
1005
- return applySelectedClientTarget();
1006
- }
1007
- });
1141
+ return loadClients({ force: true });
1008
1142
  });
1009
1143
  });
1144
+ $addTarget.on("click", function (event) {
1145
+ event.preventDefault();
1146
+ // The selected client option already carries its switch/port in its
1147
+ // data-attached-* attributes (read by getCurrentSelectionTarget),
1148
+ // so adding never needs a separate switch/port resolution.
1149
+ addCurrentTarget();
1150
+ });
1010
1151
 
1011
1152
  ensureDefaultServerSelection();
1012
1153
  $selectionMode.val(String(node.selectionMode || "switchPort"));
1013
- $action.val(String(node.action || "msgPayload"));
1014
- if (!$action.val()) {
1015
- $action.val("msgPayload");
1154
+ $controlType.val(String(node.controlType || "poe"));
1155
+ if (!$controlType.val()) {
1156
+ $controlType.val("poe");
1016
1157
  }
1158
+ renderActionOptions();
1017
1159
  makeSelectSearchable($deviceId, "Search switches");
1018
- renderSavedClientSelection();
1160
+ renderEmptyClientSelection();
1161
+ initTargetList();
1162
+ renderTargetList();
1163
+ syncPowerActionAvailability();
1019
1164
  refreshSelectionModeUi();
1020
1165
  refreshActionUi();
1021
1166
  $refreshDevices.find("i").addClass("fa-spin");
@@ -1048,6 +1193,8 @@
1048
1193
  <label for="node-input-server"><i class="fa fa-cog"></i> Connection</label>
1049
1194
  <input type="text" id="node-input-server">
1050
1195
  </div>
1196
+ <div id="node-row-picker" class="unifi-poe-picker">
1197
+ <div class="unifi-poe-picker-title"><i class="fa fa-search"></i> Pick a target, then add it</div>
1051
1198
  <div class="form-row">
1052
1199
  <label for="node-input-selectionMode"><i class="fa fa-crosshairs"></i> Search by</label>
1053
1200
  <select id="node-input-selectionMode">
@@ -1073,7 +1220,31 @@
1073
1220
  <label for="node-input-portIdx"><i class="fa fa-plug"></i> Port</label>
1074
1221
  <select id="node-input-portIdx"></select>
1075
1222
  </div>
1076
- <div class="form-row">
1223
+ <div class="form-row" id="node-row-addTarget">
1224
+ <label>&nbsp;</label>
1225
+ <a href="#" id="node-input-addTarget" class="editor-button" title="Add the selected target to the list">
1226
+ <i class="fa fa-plus"></i> Add to list
1227
+ </a>
1228
+ </div>
1229
+ </div>
1230
+ <div class="form-row" id="node-row-targets">
1231
+ <label style="vertical-align:top;"><i class="fa fa-list"></i> Clients</label>
1232
+ <div class="unifi-poe-targets-panel">
1233
+ <div id="unifi-poe-target-list" class="unifi-poe-target-list"></div>
1234
+ <div class="unifi-poe-target-footer">
1235
+ <span id="unifi-poe-target-count" class="unifi-poe-target-count">0 selected</span>
1236
+ </div>
1237
+ </div>
1238
+ </div>
1239
+ <input type="hidden" id="node-input-targets">
1240
+ <div class="form-row" id="node-row-controlType">
1241
+ <label for="node-input-controlType"><i class="fa fa-sliders"></i> Control</label>
1242
+ <select id="node-input-controlType">
1243
+ <option value="poe">PoE</option>
1244
+ <option value="port">Enable/Disable port</option>
1245
+ </select>
1246
+ </div>
1247
+ <div class="form-row" id="node-row-action">
1077
1248
  <label for="node-input-action"><i class="fa fa-power-off"></i> Action</label>
1078
1249
  <select id="node-input-action">
1079
1250
  <option value="msgPayload">POE controlled by msg.payload</option>
@@ -1085,8 +1256,8 @@
1085
1256
  </div>
1086
1257
  <div class="form-row">
1087
1258
  <div class="unifi-ultimate-card unifi-ultimate-warning">
1088
- <strong>Power actions can disconnect devices.</strong>
1089
- <div>Use Disable or Power Cycle only when you are sure the selected port is correct.</div>
1259
+ <strong>These actions can disconnect devices.</strong>
1260
+ <div>Disabling PoE, power-cycling, or disabling the port cuts power and/or traffic to whatever is attached. Use them only when you are sure the selected ports are correct.</div>
1090
1261
  </div>
1091
1262
  </div>
1092
1263
  <div id="node-row-advanced" class="unifi-ultimate-advanced">
@@ -1098,18 +1269,92 @@
1098
1269
  </div>
1099
1270
  </script>
1100
1271
 
1272
+ <style>
1273
+ .unifi-poe-picker {
1274
+ background: var(--red-ui-secondary-background, #f7f9fb);
1275
+ border: 1px solid var(--red-ui-secondary-border-color, #d9d9d9);
1276
+ border-left: 3px solid #5b9bd5;
1277
+ border-radius: 6px;
1278
+ padding: 10px 12px 2px;
1279
+ margin-bottom: 14px;
1280
+ }
1281
+ .unifi-poe-picker-title {
1282
+ font-size: 0.78em;
1283
+ text-transform: uppercase;
1284
+ letter-spacing: 0.04em;
1285
+ opacity: 0.65;
1286
+ margin-bottom: 8px;
1287
+ }
1288
+ .unifi-poe-targets-panel {
1289
+ display: inline-block;
1290
+ width: 70%;
1291
+ vertical-align: top;
1292
+ }
1293
+ .unifi-poe-target-list {
1294
+ max-height: 160px;
1295
+ overflow-y: auto;
1296
+ border: 1px solid var(--red-ui-form-input-border-color, #ccc);
1297
+ border-radius: 4px;
1298
+ padding: 4px 6px;
1299
+ background: var(--red-ui-form-input-background, #fff);
1300
+ }
1301
+ #unifi-poe-target-list .unifi-poe-target-row {
1302
+ display: flex;
1303
+ align-items: center;
1304
+ gap: 8px;
1305
+ padding: 3px 2px;
1306
+ }
1307
+ #unifi-poe-target-list .unifi-poe-target-name {
1308
+ flex: 1 1 auto;
1309
+ overflow: hidden;
1310
+ text-overflow: ellipsis;
1311
+ white-space: nowrap;
1312
+ }
1313
+ #unifi-poe-target-list .unifi-poe-target-meta {
1314
+ flex: 0 0 auto;
1315
+ opacity: 0.6;
1316
+ font-size: 0.85em;
1317
+ }
1318
+ #unifi-poe-target-list .unifi-poe-target-remove {
1319
+ flex: 0 0 auto;
1320
+ color: var(--red-ui-text-color-error, #b30000);
1321
+ text-decoration: none;
1322
+ }
1323
+ .unifi-poe-target-empty {
1324
+ opacity: 0.6;
1325
+ padding: 6px 2px;
1326
+ }
1327
+ .unifi-poe-target-footer {
1328
+ display: flex;
1329
+ justify-content: flex-end;
1330
+ margin-top: 4px;
1331
+ font-size: 0.85em;
1332
+ opacity: 0.8;
1333
+ }
1334
+ </style>
1335
+
1101
1336
  <script type="text/html" data-help-name="unifi-network-control-poe">
1102
1337
  <p><a href="https://www.youtube.com/watch?v=ZOq7M5mgUBk&list=PL9Yh1bjbLAYrWKtMlopN0swuQXbdJ8MFJ" target="_blank" rel="noopener noreferrer"><img src="resources/node-red-contrib-unifi-ultimate/logos/youtube-icon.svg" alt="YouTube" width="24" height="18" style="vertical-align:text-bottom; margin-right:6px;">Youtube Tutorials</a></p>
1103
1338
 
1104
- <p>Controls PoE on a selected UniFi switch port.</p>
1339
+ <p>Controls PoE on a list of UniFi switch ports. Build the list by picking a target (a switch port, or a client whose uplink switch/port is resolved automatically) and clicking <b>Add to list</b>. When triggered, the configured action runs on every target in the list and a single summary message is emitted.</p>
1105
1340
 
1106
1341
  <h3>Configuration</h3>
1107
1342
  <p><b>Connection</b> selects the shared UniFi Network config node.</p>
1108
- <p><b>Search by</b> chooses how to target the port: select <code>Switch + Port</code> directly, or select a <code>Client</code> and let the node fill in the connected switch and port.</p>
1343
+ <p><b>Search by</b> chooses how to pick a target before adding it: select <code>Switch + Port</code> directly, or select a <code>Client</code> and let the node fill in the connected switch and port.</p>
1109
1344
  <p><b>Switch</b> selects the adopted UniFi switch. The selector is searchable.</p>
1110
1345
  <p><b>Client</b> lists clients with known switch and port mapping. The selector is searchable and shows the user-defined client name (e.g. "iPhone di Massimo") when set, otherwise the device hostname.</p>
1111
1346
  <p><b>Port</b> selects the physical port index. Port labels include connected clients or downstream UniFi devices when available.</p>
1112
- <p><b>Action</b> executes the configured PoE operation. <code>POE controlled by msg.payload</code> maps incoming payloads to PoE mode (<code>true</code> enables PoE, <code>false</code> disables PoE). Enable and Disable update the UniFi port override (<code>poe_mode</code> auto/off). Power Cycle uses the official Network port action. <code>Emit Power Consumption</code> emits power values from the shared observer in the config node.</p>
1347
+ <p><b>Add to list</b> appends the currently selected target (switch port or resolved client) to the <b>Clients</b> list. Duplicates (same switch and port) are ignored. Remove a target with the ✕ button next to it.</p>
1348
+ <p><b>Control</b> chooses what is controlled on each target port:</p>
1349
+ <ul>
1350
+ <li><code>PoE</code> — controls Power-over-Ethernet on the port (the attached device keeps its link but loses/gains power).</li>
1351
+ <li><code>Enable/Disable port</code> — administratively enables or disables the whole switch port, exactly like the UniFi <em>Port State</em> toggle. Disabling cuts <em>all</em> traffic and PoE on that port, disconnecting whatever is attached. Implemented through the UniFi port override <code>forward</code> field (verified against the controller): Disable sets <code>forward=disabled</code> and preserves the rest of the port config. Enable acts only on a disabled port (an already-enabled port is left untouched): it sets <code>forward=all</code> and, if the port had been disabled from the UniFi UI (which also blocks VLANs and clears the native network), it restores <code>tagged_vlan_mgmt=auto</code>, <code>port_security_enabled=false</code> and the site default native network.</li>
1352
+ </ul>
1353
+ <p><b>Action</b> is applied to <em>every</em> target in the list, and its choices depend on <b>Control</b>:</p>
1354
+ <ul>
1355
+ <li><b>PoE:</b> <code>POE controlled by msg.payload</code> (<code>true</code> enables, <code>false</code> disables), <code>Enable PoE</code>, <code>Disable PoE</code>, <code>Power Cycle</code>, and <code>Emit Power Consumption</code> (single target only).</li>
1356
+ <li><b>Enable/Disable port:</b> <code>Port controlled by msg.payload</code> (<code>true</code> enables the port, <code>false</code> disables it), <code>Enable port</code>, and <code>Disable port</code>.</li>
1357
+ </ul>
1113
1358
  <p><b>Power poll interval</b> for emit action is configured globally in <code>Unifi Network Config</code>. This node does not run its own timer.</p>
1114
1359
  <p>Request timeout is handled automatically by the node.</p>
1115
1360
  <p><b>Name</b> is the node name shown in the editor and is updated only when you manually select a different switch or client target.</p>
@@ -1125,22 +1370,21 @@
1125
1370
  <h3>Outputs</h3>
1126
1371
  <dl class="message-properties">
1127
1372
  <dt>Output 1 — result</dt>
1128
- <dd>Emitted after the configured action completes successfully.</dd>
1129
- <dt class="optional">msg.payload</dt>
1130
- <dd>API response payload.</dd>
1373
+ <dd>A single summary message emitted after the action has been attempted on every target in the list. Per-target failures are reported inside the summary, not on the error output.</dd>
1374
+ <dt class="optional">msg.payload.action</dt>
1375
+ <dd>The action applied to the list (e.g. <code>DISABLE_POE</code>).</dd>
1376
+ <dt class="optional">msg.payload.total / ok / failed</dt>
1377
+ <dd>Counts of targets processed, succeeded, and failed.</dd>
1378
+ <dt class="optional">msg.payload.results</dt>
1379
+ <dd>Array with one entry per target: <code>name</code>, <code>deviceId</code>, <code>portIdx</code>, <code>action</code>, <code>ok</code>, and either <code>portName</code>/<code>portPowerW</code>/<code>powerConsumptionSwitchTotal</code> on success or <code>error</code> on failure.</dd>
1131
1380
  <dt class="optional">msg.topic</dt>
1132
1381
  <dd>Node name from the editor.</dd>
1133
- <dt class="optional">msg.deviceName</dt>
1134
- <dd>Remembered name of the selected switch or client.</dd>
1135
1382
  <dt class="optional">msg.eventName</dt>
1136
1383
  <dd>Action that produced the message.</dd>
1137
1384
  <dt class="optional">msg.details.unifiNetworkPoe</dt>
1138
- <dd>Metadata with device, site, action, and port details. Includes <code>portPowerW</code> for the selected port when available.</dd>
1139
- <dt class="optional">msg.payload.powerConsumptionSwitchTotal</dt>
1140
- <dd>Sum of PoE power draw for all switch ports (watts) when available.</dd>
1141
- <dt class="optional">msg.payload.portPowerW / msg.payload.powerChanged</dt>
1142
- <dd>Available in power-consumption emit messages.</dd>
1385
+ <dd>Summary metadata (action and total/ok/failed counts).</dd>
1143
1386
  </dl>
1387
+ <p>The <code>Emit Power Consumption</code> action (single target only) keeps its original per-port message shape, including <code>msg.payload.portPowerW</code>, <code>msg.payload.powerConsumptionSwitchTotal</code> and <code>msg.payload.powerChanged</code>.</p>
1144
1388
  <dl class="message-properties">
1145
1389
  <dt>Output 2 — error</dt>
1146
1390
  <dd>Emitted when the action fails (API error, timeout, or configuration problem). The node status also turns red. Errors are additionally forwarded to any connected <code>catch</code> node.</dd>
@@ -1185,24 +1429,27 @@
1185
1429
  </table>
1186
1430
  <p>Example output (pin 1):</p>
1187
1431
  <pre><code>{
1188
- "topic": "POE Soffitta Port 2",
1189
- "deviceName": "Soffitta",
1190
- "eventName": "request:enable",
1432
+ "topic": "Clients Control",
1433
+ "eventName": "request:DISABLE_POE",
1191
1434
  "payload": {
1192
- "status": "ok",
1193
- "deviceName": "Soffitta",
1194
- "portIdx": 2,
1195
- "portName": "Port 2",
1196
- "portPowerW": 2.6,
1197
- "powerConsumptionSwitchTotal": 36.4
1435
+ "action": "DISABLE_POE",
1436
+ "total": 3,
1437
+ "ok": 2,
1438
+ "failed": 1,
1439
+ "results": [
1440
+ { "name": "UA-Intercom → Sala tecnica p5", "deviceId": "…", "portIdx": 5,
1441
+ "action": "DISABLE_POE", "ok": true, "portName": "Port 5", "portPowerW": 4.1 },
1442
+ { "name": "Caldaia p2", "deviceId": "…", "portIdx": 2,
1443
+ "action": "DISABLE_POE", "ok": true },
1444
+ { "name": "NAS p8", "deviceId": "…", "portIdx": 8,
1445
+ "action": "DISABLE_POE", "ok": false, "error": "PoE control request failed (504)." }
1446
+ ]
1198
1447
  },
1199
1448
  "details": {
1200
1449
  "unifiNetworkPoe": {
1201
1450
  "nodeType": "poe-control",
1202
- "action": "enable",
1203
- "portIdx": 2,
1204
- "portPowerW": 2.6,
1205
- "powerConsumptionSwitchTotal": 36.4
1451
+ "action": "DISABLE_POE",
1452
+ "total": 3, "ok": 2, "failed": 1
1206
1453
  }
1207
1454
  }
1208
1455
  }</code></pre>