node-red-contrib-unifi-ultimate 1.0.7 → 1.0.9
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 +17 -16
- package/nodes/unifi-access-config.html +5 -4
- package/nodes/unifi-access-device.html +5 -4
- package/nodes/unifi-network-config.html +5 -4
- package/nodes/unifi-network-config.js +88 -197
- package/nodes/unifi-network-control-poe.html +421 -164
- package/nodes/unifi-network-control-poe.js +360 -95
- package/nodes/unifi-network-device.html +3 -3
- package/nodes/unifi-network-presence.html +5 -4
- package/nodes/unifi-network-restart.html +8 -1
- package/nodes/unifi-protect-config.html +5 -4
- package/nodes/unifi-protect-device.html +5 -4
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<link rel="stylesheet" type="text/css"
|
|
1
|
+
<link rel="stylesheet" type="text/css"
|
|
2
|
+
href="resources/node-red-contrib-unifi-ultimate/editor/unifi-ultimate-editor-common.css">
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
<script type="text/javascript">
|
|
@@ -10,39 +11,37 @@
|
|
|
10
11
|
server: { value: "", type: "unifi-network-config", required: true },
|
|
11
12
|
selectionMode: { value: "switchPort", required: true },
|
|
12
13
|
clientLookupId: { value: "" },
|
|
13
|
-
deviceId: { value: ""
|
|
14
|
+
deviceId: { value: "" },
|
|
14
15
|
deviceName: { value: "" },
|
|
15
|
-
portIdx: { value: 1
|
|
16
|
-
|
|
16
|
+
portIdx: { value: 1 },
|
|
17
|
+
controlType: { value: "poe", required: true },
|
|
18
|
+
action: { value: "msgPayload", required: true },
|
|
19
|
+
targets: {
|
|
20
|
+
value: "[]",
|
|
21
|
+
validate: function (value) {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(value || "[]");
|
|
24
|
+
return Array.isArray(parsed) && parsed.length > 0;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
},
|
|
18
31
|
inputs: 1,
|
|
19
32
|
outputs: 2,
|
|
20
33
|
icon: "unifi-u-logo-light-network.svg",
|
|
21
|
-
paletteLabel: "Control
|
|
34
|
+
paletteLabel: "Clients Control",
|
|
22
35
|
outputLabels: ["result", "error"],
|
|
23
36
|
label: function () {
|
|
24
|
-
return this.name || "Control
|
|
37
|
+
return this.name || "Clients Control";
|
|
25
38
|
},
|
|
26
39
|
oneditsave: function () {
|
|
40
|
+
// The clients list is persisted through the hidden #node-input-targets
|
|
41
|
+
// field. Here we only keep the dynamic input-pin visibility in sync:
|
|
42
|
+
// the streaming power-observation action accepts no input trigger.
|
|
27
43
|
const actionValue = String($("#node-input-action").val() || "").trim().toLowerCase();
|
|
28
44
|
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
45
|
this.inputs = opensObservation ? 0 : 1;
|
|
47
46
|
},
|
|
48
47
|
oneditprepare: function () {
|
|
@@ -54,6 +53,8 @@
|
|
|
54
53
|
const $deviceId = $("#node-input-deviceId");
|
|
55
54
|
const $clientLookupId = $("#node-input-clientLookupId");
|
|
56
55
|
const $portIdx = $("#node-input-portIdx");
|
|
56
|
+
const $controlType = $("#node-input-controlType");
|
|
57
|
+
const $controlTypeRow = $("#node-row-controlType");
|
|
57
58
|
const $action = $("#node-input-action");
|
|
58
59
|
const $refreshDevices = $("#node-input-refreshDevices");
|
|
59
60
|
const $refreshClients = $("#node-input-refreshClients");
|
|
@@ -64,6 +65,11 @@
|
|
|
64
65
|
const $actionRow = $action.closest(".form-row");
|
|
65
66
|
const $warningRow = $(".unifi-ultimate-warning").closest(".form-row");
|
|
66
67
|
const $advancedRow = $("#node-row-advanced");
|
|
68
|
+
const $addTarget = $("#node-input-addTarget");
|
|
69
|
+
const $addRow = $("#node-row-addTarget");
|
|
70
|
+
const $pickerBox = $("#node-row-picker");
|
|
71
|
+
const $targetsRow = $("#node-row-targets");
|
|
72
|
+
let targetList = [];
|
|
67
73
|
let suspendChangeHandling = false;
|
|
68
74
|
let isInitializingEditor = true;
|
|
69
75
|
let clientTargetsPopulated = false;
|
|
@@ -83,16 +89,190 @@
|
|
|
83
89
|
const hasSwitch = hasSelection($deviceId);
|
|
84
90
|
const hasPort = hasSelection($portIdx);
|
|
85
91
|
const hasClient = hasSelection($clientLookupId);
|
|
86
|
-
|
|
92
|
+
// A "current selection" is what the Add button would append; the
|
|
93
|
+
// action and downstream rows depend on the accumulated list.
|
|
94
|
+
const hasCurrentSelection = mode === "client" ? hasClient : (hasSwitch && hasPort);
|
|
95
|
+
const hasList = targetList.length > 0;
|
|
87
96
|
const hasAction = hasSelection($action);
|
|
88
97
|
|
|
98
|
+
$pickerBox.toggle(hasServer);
|
|
89
99
|
$selectionModeRow.toggle(hasServer);
|
|
90
100
|
$rowSwitch.toggle(hasServer && mode === "switchPort");
|
|
91
101
|
$rowPort.toggle(hasServer && mode === "switchPort" && hasSwitch);
|
|
92
102
|
$rowClient.toggle(hasServer && mode === "client");
|
|
93
|
-
$
|
|
94
|
-
$
|
|
95
|
-
$
|
|
103
|
+
$addRow.toggle(hasServer && hasCurrentSelection);
|
|
104
|
+
$targetsRow.toggle(hasServer);
|
|
105
|
+
$controlTypeRow.toggle(hasServer && hasList);
|
|
106
|
+
$actionRow.toggle(hasServer && hasList);
|
|
107
|
+
$warningRow.toggle(hasServer && hasList && hasAction);
|
|
108
|
+
$advancedRow.toggle(hasServer && hasList && hasAction);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function targetKey(target) {
|
|
112
|
+
return String(target.deviceId) + "|" + String(target.portIdx);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function persistTargets() {
|
|
116
|
+
$("#node-input-targets").val(JSON.stringify(targetList));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getCurrentSelectionTarget() {
|
|
120
|
+
if (getSelectionMode() === "client") {
|
|
121
|
+
const $selected = $clientLookupId.find("option:selected");
|
|
122
|
+
const deviceId = String($selected.attr("data-attached-device-id") || "").trim();
|
|
123
|
+
const portRaw = String($selected.attr("data-attached-port-idx") || "").trim();
|
|
124
|
+
const clientId = String($clientLookupId.val() || "").trim();
|
|
125
|
+
const portIdx = Number(portRaw);
|
|
126
|
+
if (!deviceId || portRaw === "" || !Number.isFinite(portIdx) || !clientId) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const clientName = String($selected.attr("data-client-name") || "").trim();
|
|
130
|
+
const switchName = String($selected.attr("data-attached-device-name") || "Switch").trim();
|
|
131
|
+
return {
|
|
132
|
+
deviceId: deviceId,
|
|
133
|
+
portIdx: portIdx,
|
|
134
|
+
clientId: clientId,
|
|
135
|
+
name: (clientName || clientId) + " → " + switchName + " p" + portIdx
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const deviceId = String($deviceId.val() || "").trim();
|
|
140
|
+
const portRaw = String($portIdx.val() || "").trim();
|
|
141
|
+
const portIdx = Number(portRaw);
|
|
142
|
+
if (!deviceId || deviceId === "_ADD_" || portRaw === "" || !Number.isFinite(portIdx)) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const deviceName = getSelectedDeviceName() || deviceId;
|
|
146
|
+
return {
|
|
147
|
+
deviceId: deviceId,
|
|
148
|
+
portIdx: portIdx,
|
|
149
|
+
clientId: "",
|
|
150
|
+
name: deviceName + " p" + portIdx
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function renderTargetList() {
|
|
155
|
+
const $list = $("#unifi-poe-target-list");
|
|
156
|
+
$list.empty();
|
|
157
|
+
|
|
158
|
+
if (targetList.length === 0) {
|
|
159
|
+
$list.append(
|
|
160
|
+
$("<div class='unifi-poe-target-empty'></div>")
|
|
161
|
+
.text("No clients added yet. Pick a target above and click \"Add to list\".")
|
|
162
|
+
);
|
|
163
|
+
} else {
|
|
164
|
+
targetList.forEach(function (target, index) {
|
|
165
|
+
const $row = $("<div class='unifi-poe-target-row'></div>");
|
|
166
|
+
$row.append(
|
|
167
|
+
$("<span class='unifi-poe-target-name'></span>")
|
|
168
|
+
.text(target.name || (target.deviceId + " p" + target.portIdx))
|
|
169
|
+
);
|
|
170
|
+
$row.append($("<span class='unifi-poe-target-meta'></span>").text("p" + target.portIdx));
|
|
171
|
+
const $remove = $("<a href='#' class='unifi-poe-target-remove' title='Remove'><i class='fa fa-times'></i></a>");
|
|
172
|
+
$remove.on("click", function (event) {
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
targetList.splice(index, 1);
|
|
175
|
+
renderTargetList();
|
|
176
|
+
syncPowerActionAvailability();
|
|
177
|
+
refreshSummary();
|
|
178
|
+
});
|
|
179
|
+
$row.append($remove);
|
|
180
|
+
$list.append($row);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
$("#unifi-poe-target-count").text(targetList.length + " selected");
|
|
185
|
+
persistTargets();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function addCurrentTarget() {
|
|
189
|
+
const target = getCurrentSelectionTarget();
|
|
190
|
+
if (!target) {
|
|
191
|
+
RED.notify("Select a switch port or a client first.", "warning");
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (targetList.some(function (existing) { return targetKey(existing) === targetKey(target); })) {
|
|
195
|
+
RED.notify("That port is already in the list.", "info");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
targetList.push(target);
|
|
200
|
+
renderTargetList();
|
|
201
|
+
syncPowerActionAvailability();
|
|
202
|
+
refreshSummary();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function syncPowerActionAvailability() {
|
|
206
|
+
// The streaming "Emit Power Consumption" action only makes sense
|
|
207
|
+
// for a single target, so it is disabled for lists of 0 or 2+.
|
|
208
|
+
const $option = $action.find("option[value='emitPowerConsumption']");
|
|
209
|
+
const allowed = targetList.length === 1;
|
|
210
|
+
$option.prop("disabled", !allowed);
|
|
211
|
+
if (!allowed && getSelectedActionValue() === "emitpowerconsumption") {
|
|
212
|
+
$action.val("msgPayload");
|
|
213
|
+
refreshActionUi();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function initTargetList() {
|
|
218
|
+
let stored = [];
|
|
219
|
+
try {
|
|
220
|
+
if (Array.isArray(node.targets)) {
|
|
221
|
+
stored = node.targets;
|
|
222
|
+
} else if (typeof node.targets === "string" && node.targets.trim()) {
|
|
223
|
+
stored = JSON.parse(node.targets);
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
stored = [];
|
|
227
|
+
}
|
|
228
|
+
if (!Array.isArray(stored)) {
|
|
229
|
+
stored = [];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const seen = {};
|
|
233
|
+
targetList = stored.map(function (entry) {
|
|
234
|
+
if (!entry || typeof entry !== "object") {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const deviceId = String(entry.deviceId || "").trim();
|
|
238
|
+
const portIdx = Number(entry.portIdx);
|
|
239
|
+
if (!deviceId || !Number.isFinite(portIdx)) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
deviceId: deviceId,
|
|
244
|
+
portIdx: portIdx,
|
|
245
|
+
clientId: String(entry.clientId || "").trim(),
|
|
246
|
+
name: String(entry.name || "").trim()
|
|
247
|
+
};
|
|
248
|
+
}).filter(function (entry) {
|
|
249
|
+
if (!entry) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const key = targetKey(entry);
|
|
253
|
+
if (seen[key]) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
seen[key] = true;
|
|
257
|
+
return true;
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// Migrate a legacy single-target node into a one-entry list.
|
|
261
|
+
if (targetList.length === 0) {
|
|
262
|
+
const legacyDeviceId = String(node.deviceId || "").trim();
|
|
263
|
+
const legacyPortRaw = String(node.portIdx === undefined || node.portIdx === null ? "" : node.portIdx).trim();
|
|
264
|
+
const legacyPort = Number(legacyPortRaw);
|
|
265
|
+
if (legacyDeviceId && legacyPortRaw !== "" && Number.isFinite(legacyPort)) {
|
|
266
|
+
targetList.push({
|
|
267
|
+
deviceId: legacyDeviceId,
|
|
268
|
+
portIdx: legacyPort,
|
|
269
|
+
clientId: String(node.clientLookupId || "").trim(),
|
|
270
|
+
name: String(node.deviceName || "").trim() || (legacyDeviceId + " p" + legacyPort)
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
persistTargets();
|
|
96
276
|
}
|
|
97
277
|
|
|
98
278
|
function setClientWaitOverlay(visible, message) {
|
|
@@ -127,6 +307,38 @@
|
|
|
127
307
|
return String($action.val() || node.action || "msgPayload").trim().toLowerCase();
|
|
128
308
|
}
|
|
129
309
|
|
|
310
|
+
function getControlType() {
|
|
311
|
+
return String($controlType.val() || node.controlType || "poe").trim() === "port" ? "port" : "poe";
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function renderActionOptions() {
|
|
315
|
+
// The action list depends on the chosen control domain. PoE keeps
|
|
316
|
+
// its full set; port mode only enables/disables the switch port.
|
|
317
|
+
const controlType = getControlType();
|
|
318
|
+
const current = String($action.val() || node.action || "msgPayload").trim();
|
|
319
|
+
const options = controlType === "port"
|
|
320
|
+
? [
|
|
321
|
+
["msgPayload", "Port controlled by msg.payload"],
|
|
322
|
+
["enable", "Enable port"],
|
|
323
|
+
["disable", "Disable port"]
|
|
324
|
+
]
|
|
325
|
+
: [
|
|
326
|
+
["msgPayload", "POE controlled by msg.payload"],
|
|
327
|
+
["enable", "Enable PoE"],
|
|
328
|
+
["disable", "Disable PoE"],
|
|
329
|
+
["cycle", "Power Cycle"],
|
|
330
|
+
["emitPowerConsumption", "Emit Power Consumption"]
|
|
331
|
+
];
|
|
332
|
+
|
|
333
|
+
$action.empty();
|
|
334
|
+
options.forEach(function (option) {
|
|
335
|
+
$action.append($("<option></option>").val(option[0]).text(option[1]));
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const hasCurrent = options.some(function (option) { return option[0] === current; });
|
|
339
|
+
$action.val(hasCurrent ? current : "msgPayload");
|
|
340
|
+
}
|
|
341
|
+
|
|
130
342
|
function selectedActionObservesPower() {
|
|
131
343
|
return ["emitpowerconsumption"].includes(getSelectedActionValue());
|
|
132
344
|
}
|
|
@@ -675,42 +887,25 @@
|
|
|
675
887
|
refreshSummary();
|
|
676
888
|
}
|
|
677
889
|
|
|
678
|
-
function
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
890
|
+
function renderEmptyClientSelection() {
|
|
891
|
+
// Open with an empty Client picker: restoring a saved client would
|
|
892
|
+
// trigger a pointless switch/port resolution on every open. The
|
|
893
|
+
// configured targets already live in the list, and the picker is
|
|
894
|
+
// only used to add new ones.
|
|
683
895
|
suspendChangeHandling = true;
|
|
684
896
|
try {
|
|
685
897
|
$clientLookupId.empty();
|
|
686
898
|
$clientLookupId.append($("<option></option>").val("").text("Choose a client target"));
|
|
687
|
-
|
|
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
|
-
}
|
|
899
|
+
$clientLookupId.val("");
|
|
704
900
|
} finally {
|
|
705
901
|
suspendChangeHandling = false;
|
|
706
902
|
}
|
|
707
903
|
|
|
708
904
|
clientTargetsLoading = false;
|
|
709
|
-
clientTargetsPopulated =
|
|
905
|
+
clientTargetsPopulated = false;
|
|
710
906
|
makeSelectSearchable($clientLookupId, "Search clients");
|
|
711
907
|
bindLazyClientLookupLoad();
|
|
712
908
|
updateDerivedTargetFieldsState();
|
|
713
|
-
rememberSelectedTargetName();
|
|
714
909
|
refreshSummary();
|
|
715
910
|
}
|
|
716
911
|
|
|
@@ -842,58 +1037,6 @@
|
|
|
842
1037
|
return clientsRequestPromise;
|
|
843
1038
|
}
|
|
844
1039
|
|
|
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
1040
|
function loadEditorData(options) {
|
|
898
1041
|
const settings = options && typeof options === "object" ? options : {};
|
|
899
1042
|
const shouldLoadClients = settings.loadClients === true;
|
|
@@ -905,10 +1048,6 @@
|
|
|
905
1048
|
force: settings.forceClients === true,
|
|
906
1049
|
showLoading: settings.showClientsLoading !== false
|
|
907
1050
|
});
|
|
908
|
-
}).then(function () {
|
|
909
|
-
if (getSelectionMode() === "client") {
|
|
910
|
-
return applySelectedClientTarget();
|
|
911
|
-
}
|
|
912
1051
|
}).finally(function () {
|
|
913
1052
|
refreshSummary();
|
|
914
1053
|
});
|
|
@@ -953,6 +1092,12 @@
|
|
|
953
1092
|
});
|
|
954
1093
|
|
|
955
1094
|
$portIdx.on("change", refreshSummary);
|
|
1095
|
+
$controlType.on("change", function () {
|
|
1096
|
+
renderActionOptions();
|
|
1097
|
+
syncPowerActionAvailability();
|
|
1098
|
+
refreshActionUi();
|
|
1099
|
+
refreshSummary();
|
|
1100
|
+
});
|
|
956
1101
|
$action.on("change", function () {
|
|
957
1102
|
refreshActionUi();
|
|
958
1103
|
refreshSummary();
|
|
@@ -964,10 +1109,11 @@
|
|
|
964
1109
|
refreshSelectionModeUi();
|
|
965
1110
|
rememberSelectedTargetName();
|
|
966
1111
|
if (getSelectionMode() === "client") {
|
|
1112
|
+
// Only load the client dropdown so the user can pick one. The
|
|
1113
|
+
// switch/port for the chosen client lives on the option's
|
|
1114
|
+
// data-attached-* attributes, so there is nothing to resolve.
|
|
967
1115
|
withClientWait("Loading client targets...", function () {
|
|
968
|
-
return loadClients({ showLoading: false })
|
|
969
|
-
return applySelectedClientTarget();
|
|
970
|
-
});
|
|
1116
|
+
return loadClients({ showLoading: false });
|
|
971
1117
|
});
|
|
972
1118
|
} else {
|
|
973
1119
|
refreshSummary();
|
|
@@ -980,42 +1126,42 @@
|
|
|
980
1126
|
rememberSelectedTargetName();
|
|
981
1127
|
const isUserSelection = $clientLookupId.data("unifi-user-selection") === true;
|
|
982
1128
|
$clientLookupId.removeData("unifi-user-selection");
|
|
983
|
-
if (
|
|
984
|
-
|
|
985
|
-
return applySelectedClientTarget({ syncName: isUserSelection });
|
|
986
|
-
});
|
|
987
|
-
} else {
|
|
988
|
-
refreshSummary();
|
|
1129
|
+
if (isUserSelection) {
|
|
1130
|
+
syncNameFromSelection();
|
|
989
1131
|
}
|
|
1132
|
+
refreshSummary();
|
|
990
1133
|
});
|
|
991
1134
|
|
|
992
1135
|
$refreshDevices.on("click", function (event) {
|
|
993
1136
|
event.preventDefault();
|
|
994
|
-
loadDevices()
|
|
995
|
-
if (getSelectionMode() === "client") {
|
|
996
|
-
return applySelectedClientTarget();
|
|
997
|
-
}
|
|
998
|
-
});
|
|
1137
|
+
loadDevices();
|
|
999
1138
|
});
|
|
1000
1139
|
$refreshClients.on("click", function (event) {
|
|
1001
1140
|
event.preventDefault();
|
|
1002
1141
|
withClientWait("Loading client targets...", function () {
|
|
1003
|
-
return loadClients({ force: true })
|
|
1004
|
-
if (getSelectionMode() === "client") {
|
|
1005
|
-
return applySelectedClientTarget();
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1142
|
+
return loadClients({ force: true });
|
|
1008
1143
|
});
|
|
1009
1144
|
});
|
|
1145
|
+
$addTarget.on("click", function (event) {
|
|
1146
|
+
event.preventDefault();
|
|
1147
|
+
// The selected client option already carries its switch/port in its
|
|
1148
|
+
// data-attached-* attributes (read by getCurrentSelectionTarget),
|
|
1149
|
+
// so adding never needs a separate switch/port resolution.
|
|
1150
|
+
addCurrentTarget();
|
|
1151
|
+
});
|
|
1010
1152
|
|
|
1011
1153
|
ensureDefaultServerSelection();
|
|
1012
1154
|
$selectionMode.val(String(node.selectionMode || "switchPort"));
|
|
1013
|
-
$
|
|
1014
|
-
if (!$
|
|
1015
|
-
$
|
|
1155
|
+
$controlType.val(String(node.controlType || "poe"));
|
|
1156
|
+
if (!$controlType.val()) {
|
|
1157
|
+
$controlType.val("poe");
|
|
1016
1158
|
}
|
|
1159
|
+
renderActionOptions();
|
|
1017
1160
|
makeSelectSearchable($deviceId, "Search switches");
|
|
1018
|
-
|
|
1161
|
+
renderEmptyClientSelection();
|
|
1162
|
+
initTargetList();
|
|
1163
|
+
renderTargetList();
|
|
1164
|
+
syncPowerActionAvailability();
|
|
1019
1165
|
refreshSelectionModeUi();
|
|
1020
1166
|
refreshActionUi();
|
|
1021
1167
|
$refreshDevices.find("i").addClass("fa-spin");
|
|
@@ -1033,7 +1179,7 @@
|
|
|
1033
1179
|
<img class="unifi-ultimate-product-logo" src="resources/node-red-contrib-unifi-ultimate/logos/unifi-network-black.svg" alt="UniFi Network logo" onerror="this.closest('.unifi-ultimate-product-logo-row').style.display='none';">
|
|
1034
1180
|
</div>
|
|
1035
1181
|
<div class="form-row unifi-ultimate-hero">
|
|
1036
|
-
<a class="unifi-ultimate-youtube-link" href="https://
|
|
1182
|
+
<a class="unifi-ultimate-youtube-link" href="https://youtube.com/playlist?list=PL9Yh1bjbLAYrWKtMlopN0swuQXbdJ8MFJ&si=4MmW1nNTCLrJtEHv" target="_blank" rel="noopener noreferrer">
|
|
1037
1183
|
<img src="resources/node-red-contrib-unifi-ultimate/logos/youtube-icon.svg" alt="YouTube" width="24" height="18">
|
|
1038
1184
|
<span>Youtube Tutorials</span>
|
|
1039
1185
|
</a>
|
|
@@ -1048,6 +1194,8 @@
|
|
|
1048
1194
|
<label for="node-input-server"><i class="fa fa-cog"></i> Connection</label>
|
|
1049
1195
|
<input type="text" id="node-input-server">
|
|
1050
1196
|
</div>
|
|
1197
|
+
<div id="node-row-picker" class="unifi-poe-picker">
|
|
1198
|
+
<div class="unifi-poe-picker-title"><i class="fa fa-search"></i> Pick a target, then add it</div>
|
|
1051
1199
|
<div class="form-row">
|
|
1052
1200
|
<label for="node-input-selectionMode"><i class="fa fa-crosshairs"></i> Search by</label>
|
|
1053
1201
|
<select id="node-input-selectionMode">
|
|
@@ -1073,7 +1221,31 @@
|
|
|
1073
1221
|
<label for="node-input-portIdx"><i class="fa fa-plug"></i> Port</label>
|
|
1074
1222
|
<select id="node-input-portIdx"></select>
|
|
1075
1223
|
</div>
|
|
1076
|
-
<div class="form-row">
|
|
1224
|
+
<div class="form-row" id="node-row-addTarget">
|
|
1225
|
+
<label> </label>
|
|
1226
|
+
<a href="#" id="node-input-addTarget" class="editor-button" title="Add the selected target to the list">
|
|
1227
|
+
<i class="fa fa-plus"></i> Add to list
|
|
1228
|
+
</a>
|
|
1229
|
+
</div>
|
|
1230
|
+
</div>
|
|
1231
|
+
<div class="form-row" id="node-row-targets">
|
|
1232
|
+
<label style="vertical-align:top;"><i class="fa fa-list"></i> Clients</label>
|
|
1233
|
+
<div class="unifi-poe-targets-panel">
|
|
1234
|
+
<div id="unifi-poe-target-list" class="unifi-poe-target-list"></div>
|
|
1235
|
+
<div class="unifi-poe-target-footer">
|
|
1236
|
+
<span id="unifi-poe-target-count" class="unifi-poe-target-count">0 selected</span>
|
|
1237
|
+
</div>
|
|
1238
|
+
</div>
|
|
1239
|
+
</div>
|
|
1240
|
+
<input type="hidden" id="node-input-targets">
|
|
1241
|
+
<div class="form-row" id="node-row-controlType">
|
|
1242
|
+
<label for="node-input-controlType"><i class="fa fa-sliders"></i> Control</label>
|
|
1243
|
+
<select id="node-input-controlType">
|
|
1244
|
+
<option value="poe">PoE</option>
|
|
1245
|
+
<option value="port">Enable/Disable port</option>
|
|
1246
|
+
</select>
|
|
1247
|
+
</div>
|
|
1248
|
+
<div class="form-row" id="node-row-action">
|
|
1077
1249
|
<label for="node-input-action"><i class="fa fa-power-off"></i> Action</label>
|
|
1078
1250
|
<select id="node-input-action">
|
|
1079
1251
|
<option value="msgPayload">POE controlled by msg.payload</option>
|
|
@@ -1085,8 +1257,8 @@
|
|
|
1085
1257
|
</div>
|
|
1086
1258
|
<div class="form-row">
|
|
1087
1259
|
<div class="unifi-ultimate-card unifi-ultimate-warning">
|
|
1088
|
-
<strong>
|
|
1089
|
-
<div>
|
|
1260
|
+
<strong>These actions can disconnect devices.</strong>
|
|
1261
|
+
<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
1262
|
</div>
|
|
1091
1263
|
</div>
|
|
1092
1264
|
<div id="node-row-advanced" class="unifi-ultimate-advanced">
|
|
@@ -1098,18 +1270,101 @@
|
|
|
1098
1270
|
</div>
|
|
1099
1271
|
</script>
|
|
1100
1272
|
|
|
1273
|
+
<style>
|
|
1274
|
+
.unifi-poe-picker {
|
|
1275
|
+
background: var(--red-ui-secondary-background, #f7f9fb);
|
|
1276
|
+
border: 1px solid var(--red-ui-secondary-border-color, #d9d9d9);
|
|
1277
|
+
border-left: 3px solid #5b9bd5;
|
|
1278
|
+
border-radius: 6px;
|
|
1279
|
+
padding: 10px 12px 2px;
|
|
1280
|
+
margin-bottom: 14px;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
.unifi-poe-picker-title {
|
|
1284
|
+
font-size: 0.78em;
|
|
1285
|
+
text-transform: uppercase;
|
|
1286
|
+
letter-spacing: 0.04em;
|
|
1287
|
+
opacity: 0.65;
|
|
1288
|
+
margin-bottom: 8px;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
.unifi-poe-targets-panel {
|
|
1292
|
+
display: inline-block;
|
|
1293
|
+
width: 70%;
|
|
1294
|
+
vertical-align: top;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
.unifi-poe-target-list {
|
|
1298
|
+
max-height: 160px;
|
|
1299
|
+
overflow-y: auto;
|
|
1300
|
+
border: 1px solid var(--red-ui-form-input-border-color, #ccc);
|
|
1301
|
+
border-radius: 4px;
|
|
1302
|
+
padding: 4px 6px;
|
|
1303
|
+
background: var(--red-ui-form-input-background, #fff);
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
#unifi-poe-target-list .unifi-poe-target-row {
|
|
1307
|
+
display: flex;
|
|
1308
|
+
align-items: center;
|
|
1309
|
+
gap: 8px;
|
|
1310
|
+
padding: 3px 2px;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
#unifi-poe-target-list .unifi-poe-target-name {
|
|
1314
|
+
flex: 1 1 auto;
|
|
1315
|
+
overflow: hidden;
|
|
1316
|
+
text-overflow: ellipsis;
|
|
1317
|
+
white-space: nowrap;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
#unifi-poe-target-list .unifi-poe-target-meta {
|
|
1321
|
+
flex: 0 0 auto;
|
|
1322
|
+
opacity: 0.6;
|
|
1323
|
+
font-size: 0.85em;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
#unifi-poe-target-list .unifi-poe-target-remove {
|
|
1327
|
+
flex: 0 0 auto;
|
|
1328
|
+
color: var(--red-ui-text-color-error, #b30000);
|
|
1329
|
+
text-decoration: none;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
.unifi-poe-target-empty {
|
|
1333
|
+
opacity: 0.6;
|
|
1334
|
+
padding: 6px 2px;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
.unifi-poe-target-footer {
|
|
1338
|
+
display: flex;
|
|
1339
|
+
justify-content: flex-end;
|
|
1340
|
+
margin-top: 4px;
|
|
1341
|
+
font-size: 0.85em;
|
|
1342
|
+
opacity: 0.8;
|
|
1343
|
+
}
|
|
1344
|
+
</style>
|
|
1345
|
+
|
|
1101
1346
|
<script type="text/html" data-help-name="unifi-network-control-poe">
|
|
1102
|
-
<p><a href="https://
|
|
1347
|
+
<p><a href="https://youtube.com/playlist?list=PL9Yh1bjbLAYrWKtMlopN0swuQXbdJ8MFJ&si=4MmW1nNTCLrJtEHv" 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
1348
|
|
|
1104
|
-
<p>Controls PoE on a
|
|
1349
|
+
<p>Controls PoE, or enables/disables the whole switch port, 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
1350
|
|
|
1106
1351
|
<h3>Configuration</h3>
|
|
1107
1352
|
<p><b>Connection</b> selects the shared UniFi Network config node.</p>
|
|
1108
|
-
<p><b>Search by</b> chooses how to target
|
|
1353
|
+
<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
1354
|
<p><b>Switch</b> selects the adopted UniFi switch. The selector is searchable.</p>
|
|
1110
1355
|
<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
1356
|
<p><b>Port</b> selects the physical port index. Port labels include connected clients or downstream UniFi devices when available.</p>
|
|
1112
|
-
<p><b>
|
|
1357
|
+
<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>
|
|
1358
|
+
<p><b>Control</b> chooses what is controlled on each target port:</p>
|
|
1359
|
+
<ul>
|
|
1360
|
+
<li><code>PoE</code> — controls Power-over-Ethernet on the port (the attached device keeps its link but loses/gains power).</li>
|
|
1361
|
+
<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>
|
|
1362
|
+
</ul>
|
|
1363
|
+
<p><b>Action</b> is applied to <em>every</em> target in the list, and its choices depend on <b>Control</b>:</p>
|
|
1364
|
+
<ul>
|
|
1365
|
+
<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>
|
|
1366
|
+
<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>
|
|
1367
|
+
</ul>
|
|
1113
1368
|
<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
1369
|
<p>Request timeout is handled automatically by the node.</p>
|
|
1115
1370
|
<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 +1380,21 @@
|
|
|
1125
1380
|
<h3>Outputs</h3>
|
|
1126
1381
|
<dl class="message-properties">
|
|
1127
1382
|
<dt>Output 1 — result</dt>
|
|
1128
|
-
<dd>
|
|
1129
|
-
<dt class="optional">msg.payload</dt>
|
|
1130
|
-
<dd>
|
|
1383
|
+
<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>
|
|
1384
|
+
<dt class="optional">msg.payload.action</dt>
|
|
1385
|
+
<dd>The action applied to the list (e.g. <code>DISABLE_POE</code>).</dd>
|
|
1386
|
+
<dt class="optional">msg.payload.total / ok / failed</dt>
|
|
1387
|
+
<dd>Counts of targets processed, succeeded, and failed.</dd>
|
|
1388
|
+
<dt class="optional">msg.payload.results</dt>
|
|
1389
|
+
<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
1390
|
<dt class="optional">msg.topic</dt>
|
|
1132
1391
|
<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
1392
|
<dt class="optional">msg.eventName</dt>
|
|
1136
1393
|
<dd>Action that produced the message.</dd>
|
|
1137
1394
|
<dt class="optional">msg.details.unifiNetworkPoe</dt>
|
|
1138
|
-
<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>
|
|
1395
|
+
<dd>Summary metadata (action and total/ok/failed counts).</dd>
|
|
1143
1396
|
</dl>
|
|
1397
|
+
<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
1398
|
<dl class="message-properties">
|
|
1145
1399
|
<dt>Output 2 — error</dt>
|
|
1146
1400
|
<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,31 +1439,34 @@
|
|
|
1185
1439
|
</table>
|
|
1186
1440
|
<p>Example output (pin 1):</p>
|
|
1187
1441
|
<pre><code>{
|
|
1188
|
-
"topic": "
|
|
1189
|
-
"
|
|
1190
|
-
"eventName": "request:enable",
|
|
1442
|
+
"topic": "Clients Control",
|
|
1443
|
+
"eventName": "request:DISABLE_POE",
|
|
1191
1444
|
"payload": {
|
|
1192
|
-
"
|
|
1193
|
-
"
|
|
1194
|
-
"
|
|
1195
|
-
"
|
|
1196
|
-
"
|
|
1197
|
-
|
|
1445
|
+
"action": "DISABLE_POE",
|
|
1446
|
+
"total": 3,
|
|
1447
|
+
"ok": 2,
|
|
1448
|
+
"failed": 1,
|
|
1449
|
+
"results": [
|
|
1450
|
+
{ "name": "UA-Intercom → Sala tecnica p5", "deviceId": "…", "portIdx": 5,
|
|
1451
|
+
"action": "DISABLE_POE", "ok": true, "portName": "Port 5", "portPowerW": 4.1 },
|
|
1452
|
+
{ "name": "Caldaia p2", "deviceId": "…", "portIdx": 2,
|
|
1453
|
+
"action": "DISABLE_POE", "ok": true },
|
|
1454
|
+
{ "name": "NAS p8", "deviceId": "…", "portIdx": 8,
|
|
1455
|
+
"action": "DISABLE_POE", "ok": false, "error": "PoE control request failed (504)." }
|
|
1456
|
+
]
|
|
1198
1457
|
},
|
|
1199
1458
|
"details": {
|
|
1200
1459
|
"unifiNetworkPoe": {
|
|
1201
1460
|
"nodeType": "poe-control",
|
|
1202
|
-
"action": "
|
|
1203
|
-
"
|
|
1204
|
-
"portPowerW": 2.6,
|
|
1205
|
-
"powerConsumptionSwitchTotal": 36.4
|
|
1461
|
+
"action": "DISABLE_POE",
|
|
1462
|
+
"total": 3, "ok": 2, "failed": 1
|
|
1206
1463
|
}
|
|
1207
1464
|
}
|
|
1208
1465
|
}</code></pre>
|
|
1209
1466
|
<p>Example output (pin 2 — error):</p>
|
|
1210
1467
|
<pre><code>{
|
|
1211
|
-
"topic": "
|
|
1468
|
+
"topic": "Clients Control",
|
|
1212
1469
|
"payload": null,
|
|
1213
|
-
"error": { "message": "
|
|
1470
|
+
"error": { "message": "No client targets configured." }
|
|
1214
1471
|
}</code></pre>
|
|
1215
|
-
</script>
|
|
1472
|
+
</script>
|