node-red-contrib-unifi-ultimate 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +24 -24
  2. package/nodes/icons/unifi-u-logo-light-access.svg +7 -0
  3. package/nodes/icons/unifi-u-logo-light-network.svg +7 -0
  4. package/nodes/icons/unifi-u-logo-light-protect.svg +7 -0
  5. package/nodes/icons/unifi-u-logo-light.svg +5 -0
  6. package/nodes/icons/unifi-ultimate-logo.svg +5 -16
  7. package/nodes/readme-assets/UniFi Access/UniFi Access Black.png +0 -0
  8. package/nodes/readme-assets/UniFi Access/UniFi Access Black.svg +17 -0
  9. package/nodes/readme-assets/UniFi Access/UniFi Access White.png +0 -0
  10. package/nodes/readme-assets/UniFi Access/UniFi Access White.svg +17 -0
  11. package/nodes/readme-assets/UniFi Network/UniFi Network Black.png +0 -0
  12. package/nodes/readme-assets/UniFi Network/UniFi Network Black.svg +17 -0
  13. package/nodes/readme-assets/UniFi Network/UniFi Network White.png +0 -0
  14. package/nodes/readme-assets/UniFi Network/UniFi Network White.svg +17 -0
  15. package/nodes/readme-assets/UniFi Protect/UniFi Protect Black.png +0 -0
  16. package/nodes/readme-assets/UniFi Protect/UniFi Protect Black.svg +17 -0
  17. package/nodes/readme-assets/UniFi Protect/UniFi Protect White.png +0 -0
  18. package/nodes/readme-assets/UniFi Protect/UniFi Protect White.svg +17 -0
  19. package/nodes/readme-assets/ulogo-square/U-logo-dark.png +0 -0
  20. package/nodes/readme-assets/ulogo-square/U-logo-dark.svg +5 -0
  21. package/nodes/readme-assets/ulogo-square/U-logo-light.png +0 -0
  22. package/nodes/readme-assets/ulogo-square/U-logo-light.svg +5 -0
  23. package/nodes/unifi-access-config.html +5 -72
  24. package/nodes/unifi-access-device.html +8 -74
  25. package/nodes/unifi-network-config.html +4 -69
  26. package/nodes/unifi-network-control-poe.html +64 -94
  27. package/nodes/unifi-network-control-poe.js +75 -11
  28. package/nodes/unifi-network-device.html +49 -76
  29. package/nodes/unifi-network-presence.html +6 -76
  30. package/nodes/unifi-protect-config.html +4 -70
  31. package/nodes/unifi-protect-device.html +8 -74
  32. package/package.json +2 -1
  33. package/resources/editor/unifi-ultimate-editor-common.css +93 -0
  34. package/resources/logos/unifi-access-black.svg +17 -0
  35. package/resources/logos/unifi-network-black.svg +17 -0
  36. package/resources/logos/unifi-protect-black.svg +17 -0
  37. package/nodes/readme-assets/unifi-access-door-access.jpg +0 -0
  38. package/nodes/readme-assets/unifi-network-switching.jpg +0 -0
  39. package/nodes/readme-assets/unifi-protect-camera.png +0 -0
@@ -1,72 +1,5 @@
1
- <style>
2
- .unifi-ultimate-hero {
3
- margin: 0 0 14px 0;
4
- }
1
+ <link rel="stylesheet" type="text/css" href="resources/node-red-contrib-unifi-ultimate/editor/unifi-ultimate-editor-common.css">
5
2
 
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
-
46
- .unifi-ultimate-card {
47
- margin-left: 150px;
48
- padding: 13px 15px;
49
- border: 1px solid #e2e8f0;
50
- border-radius: 14px;
51
- background: #f8fafc;
52
- color: #334155;
53
- line-height: 1.45;
54
- box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
55
- }
56
-
57
- .unifi-ultimate-card strong {
58
- display: block;
59
- margin-bottom: 4px;
60
- color: #0f172a;
61
- font-weight: 600;
62
- }
63
-
64
- .unifi-ultimate-advanced {
65
- margin-top: 14px;
66
- padding-top: 10px;
67
- border-top: 1px solid #e5e7eb;
68
- }
69
- </style>
70
3
 
71
4
  <script type="text/javascript">
72
5
  RED.nodes.registerType("unifi-network-config", {
@@ -131,9 +64,11 @@
131
64
  </script>
132
65
 
133
66
  <script type="text/html" data-template-name="unifi-network-config">
67
+ <div class="form-row unifi-ultimate-product-logo-row">
68
+ <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';">
69
+ </div>
134
70
  <div class="form-row unifi-ultimate-hero">
135
71
  <div class="unifi-ultimate-hero-panel">
136
- <div class="unifi-ultimate-eyebrow">UniFi Network Connection</div>
137
72
  <strong>Connect Node-RED to your UniFi Network application.</strong>
138
73
  <span>Use a local UniFi OS host or IP address and a Network API key.</span>
139
74
  </div>
@@ -1,87 +1,5 @@
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
- }
1
+ <link rel="stylesheet" type="text/css" href="resources/node-red-contrib-unifi-ultimate/editor/unifi-ultimate-editor-common.css">
45
2
 
46
- .unifi-ultimate-card {
47
- margin-left: 150px;
48
- padding: 13px 15px;
49
- border: 1px solid #e2e8f0;
50
- border-radius: 14px;
51
- background: #f8fafc;
52
- color: #334155;
53
- line-height: 1.45;
54
- box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
55
- }
56
-
57
- .unifi-ultimate-card strong {
58
- display: block;
59
- margin-bottom: 4px;
60
- color: #0f172a;
61
- font-weight: 600;
62
- }
63
-
64
- .unifi-ultimate-advanced {
65
- margin-top: 14px;
66
- padding-top: 10px;
67
- border-top: 1px solid #e5e7eb;
68
- }
69
-
70
- .unifi-ultimate-offline-option {
71
- color: #94a3b8 !important;
72
- }
73
-
74
- .unifi-ultimate-warning {
75
- border-color: #fed7aa;
76
- background: #fff7ed;
77
- color: #7c2d12;
78
- }
79
-
80
- .unifi-ultimate-warning strong {
81
- color: #9a3412;
82
- }
83
-
84
- </style>
85
3
 
86
4
  <script type="text/javascript">
87
5
  RED.nodes.registerType("unifi-network-control-poe", {
@@ -95,13 +13,13 @@
95
13
  deviceId: { value: "", required: true },
96
14
  deviceName: { value: "" },
97
15
  portIdx: { value: 1, required: true, validate: RED.validators.number() },
98
- action: { value: "cycle", required: true },
16
+ action: { value: "msgPayload", required: true },
99
17
  powerIntervalSeconds: { value: 15, required: true, validate: RED.validators.number() },
100
18
  timeout: { value: 15000, required: true, validate: RED.validators.number() }
101
19
  },
102
20
  inputs: 1,
103
21
  outputs: 1,
104
- icon: "unifi-network-icon.svg",
22
+ icon: "unifi-u-logo-light-network.svg",
105
23
  paletteLabel: "Control POE",
106
24
  outputLabels: ["result"],
107
25
  label: function () {
@@ -139,15 +57,42 @@
139
57
  const $selectionSummary = $("#node-input-selectionSummary");
140
58
  const $selectionDetail = $("#node-input-selectionDetail");
141
59
  let suspendChangeHandling = false;
60
+ let clientTargetsPopulated = false;
61
+ let clientTargetsLoading = false;
142
62
 
143
63
  function getSelectedActionValue() {
144
- return String($action.val() || node.action || "cycle").trim().toLowerCase();
64
+ return String($action.val() || node.action || "msgPayload").trim().toLowerCase();
145
65
  }
146
66
 
147
67
  function selectedActionObservesPower() {
148
68
  return ["emitpoweratchange", "emitpoweratinterval"].includes(getSelectedActionValue());
149
69
  }
150
70
 
71
+ function selectedActionUsesPayloadControl() {
72
+ return ["msgpayload", "payload", "poecontrolledbymsgpayload"].includes(getSelectedActionValue());
73
+ }
74
+
75
+ function setSelectAndSearchDisabled($select, disabled) {
76
+ if (!$select || $select.length === 0) {
77
+ return;
78
+ }
79
+ $select.prop("disabled", disabled === true);
80
+ const selectId = String($select.attr("id") || "").trim();
81
+ if (!selectId) {
82
+ return;
83
+ }
84
+ $("#" + selectId + "-search").prop("disabled", disabled === true);
85
+ }
86
+
87
+ function setButtonDisabled($button, disabled) {
88
+ if (!$button || $button.length === 0) {
89
+ return;
90
+ }
91
+ $button.prop("disabled", disabled === true);
92
+ $button.attr("aria-disabled", disabled === true ? "true" : "false");
93
+ $button.toggleClass("disabled", disabled === true);
94
+ }
95
+
151
96
  function syncEditorInputsFlag() {
152
97
  // Persist dynamic pin visibility: stream-like power observation
153
98
  // modes do not accept input triggers.
@@ -462,13 +407,22 @@
462
407
  $rowSwitch.show();
463
408
  $rowPort.show();
464
409
  }
410
+ updateDerivedTargetFieldsState();
411
+ }
412
+
413
+ function updateDerivedTargetFieldsState() {
414
+ const isClientMode = getSelectionMode() === "client";
415
+ const disableDerived = isClientMode && (clientTargetsLoading || !clientTargetsPopulated);
416
+ setSelectAndSearchDisabled($deviceId, disableDerived);
417
+ setSelectAndSearchDisabled($portIdx, disableDerived);
418
+ setButtonDisabled($refreshDevices, disableDerived);
465
419
  }
466
420
 
467
421
  function refreshSummary() {
468
422
  const deviceName = getSelectedDeviceName();
469
423
  const clientName = getSelectedClientName();
470
424
  const mode = getSelectionMode();
471
- const actionLabel = String($action.find("option:selected").text() || "Power Cycle Port").trim();
425
+ const actionLabel = String($action.find("option:selected").text() || "POE controlled by msg.payload").trim();
472
426
  const portLabel = String($portIdx.val() || "").trim();
473
427
  const powerObserveMode = selectedActionPowerObserveMode();
474
428
  const intervalSeconds = normalizeIntervalSeconds($powerIntervalSeconds.val());
@@ -502,6 +456,10 @@
502
456
  }
503
457
  }
504
458
 
459
+ if (selectedActionUsesPayloadControl()) {
460
+ detail = "Send msg.payload=true to enable PoE, or msg.payload=false to disable PoE.";
461
+ }
462
+
505
463
  $selectionSummary.text(summary);
506
464
  $selectionDetail.text(detail);
507
465
  }
@@ -615,6 +573,7 @@
615
573
 
616
574
  function renderClients(items) {
617
575
  const currentValue = String($clientLookupId.val() || node.clientLookupId || "").trim();
576
+ let renderedTargets = 0;
618
577
  suspendChangeHandling = true;
619
578
  try {
620
579
  $clientLookupId.empty();
@@ -648,6 +607,7 @@
648
607
  $option.css("color", "#94a3b8");
649
608
  }
650
609
  $clientLookupId.append($option);
610
+ renderedTargets += 1;
651
611
  });
652
612
 
653
613
  if (currentValue && $clientLookupId.find("option[value='" + currentValue + "']").length > 0) {
@@ -660,11 +620,16 @@
660
620
  }
661
621
 
662
622
  makeSelectSearchable($clientLookupId, "Search clients");
623
+ clientTargetsLoading = false;
624
+ clientTargetsPopulated = renderedTargets > 0;
625
+ updateDerivedTargetFieldsState();
663
626
  rememberSelectedTargetName();
664
627
  refreshSummary();
665
628
  }
666
629
 
667
630
  function renderClientsLoading() {
631
+ clientTargetsLoading = true;
632
+ clientTargetsPopulated = false;
668
633
  suspendChangeHandling = true;
669
634
  try {
670
635
  $clientLookupId.empty();
@@ -682,6 +647,7 @@
682
647
  $("#node-input-clientLookupId-search")
683
648
  .val("Loading clients, please wait...")
684
649
  .prop("disabled", true);
650
+ updateDerivedTargetFieldsState();
685
651
  $selectionSummary.text("Loading client targets...");
686
652
  $selectionDetail.text("Please wait while UniFi returns clients and switch-port attachments.");
687
653
  }
@@ -912,9 +878,9 @@
912
878
 
913
879
  ensureDefaultServerSelection();
914
880
  $selectionMode.val(String(node.selectionMode || "switchPort"));
915
- $action.val(String(node.action || "cycle"));
881
+ $action.val(String(node.action || "msgPayload"));
916
882
  if (!$action.val()) {
917
- $action.val("cycle");
883
+ $action.val("msgPayload");
918
884
  }
919
885
  $powerIntervalSeconds.val(String(normalizeIntervalSeconds(node.powerIntervalSeconds)));
920
886
  makeSelectSearchable($deviceId, "Search switches");
@@ -929,9 +895,11 @@
929
895
  </script>
930
896
 
931
897
  <script type="text/html" data-template-name="unifi-network-control-poe">
898
+ <div class="form-row unifi-ultimate-product-logo-row">
899
+ <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';">
900
+ </div>
932
901
  <div class="form-row unifi-ultimate-hero">
933
902
  <div class="unifi-ultimate-hero-panel">
934
- <div class="unifi-ultimate-eyebrow">UniFi Network PoE</div>
935
903
  <strong>Control power on a switch port.</strong>
936
904
  <span>Target a switch and port directly, or pick a client and let UniFi resolve the connected port.</span>
937
905
  </div>
@@ -952,14 +920,14 @@
952
920
  <div class="form-row" id="node-row-deviceId">
953
921
  <label for="node-input-deviceId"><i class="fa fa-exchange"></i> Switch</label>
954
922
  <select id="node-input-deviceId" style="width:70%;"></select>
955
- <a href="#" id="node-input-refreshDevices" class="editor-button" style="margin-left:6px;">
923
+ <a href="#" id="node-input-refreshDevices" class="editor-button" style="margin-left:6px;" title="Refresh switches and ports" aria-label="Refresh switches and ports">
956
924
  <i class="fa fa-refresh"></i>
957
925
  </a>
958
926
  </div>
959
927
  <div class="form-row" id="node-row-clientLookupId">
960
928
  <label for="node-input-clientLookupId"><i class="fa fa-laptop"></i> Client</label>
961
929
  <select id="node-input-clientLookupId" style="width:70%;"></select>
962
- <a href="#" id="node-input-refreshClients" class="editor-button" style="margin-left:6px;">
930
+ <a href="#" id="node-input-refreshClients" class="editor-button" style="margin-left:6px;" title="Refresh clients" aria-label="Refresh clients">
963
931
  <i class="fa fa-refresh"></i>
964
932
  </a>
965
933
  </div>
@@ -971,6 +939,7 @@
971
939
  <div class="form-row">
972
940
  <label for="node-input-action"><i class="fa fa-power-off"></i> Action</label>
973
941
  <select id="node-input-action">
942
+ <option value="msgPayload">POE controlled by msg.payload</option>
974
943
  <option value="enable">Enable PoE</option>
975
944
  <option value="disable">Disable PoE</option>
976
945
  <option value="cycle">Power Cycle</option>
@@ -1016,7 +985,7 @@
1016
985
  <p><b>Switch</b> selects the adopted UniFi switch. The selector is searchable.</p>
1017
986
  <p><b>Client</b> lists clients with known switch and port mapping. The selector is searchable.</p>
1018
987
  <p><b>Port</b> selects the physical port index. Port labels include connected clients or downstream UniFi devices when available.</p>
1019
- <p><b>Action</b> executes the configured PoE operation. Enable and Disable update the UniFi port override (<code>poe_mode</code> auto/off). Power Cycle uses the official Network port action. You can also use <code>Emit Power Consumption at change</code> and <code>Emit Power Consumption at fixed intervals</code>.</p>
988
+ <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. You can also use <code>Emit Power Consumption at change</code> and <code>Emit Power Consumption at fixed intervals</code>.</p>
1020
989
  <p><b>Interval (s)</b> is used by power-consumption emit actions and has a minimum of <code>5</code> seconds.</p>
1021
990
  <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>
1022
991
  <p><b>Timeout</b> controls the request timeout in milliseconds.</p>
@@ -1025,7 +994,8 @@
1025
994
  <ul>
1026
995
  <li>When using <code>Emit Power Consumption at change</code> or <code>Emit Power Consumption at fixed intervals</code>, the input pin is hidden and listening starts automatically after deploy/restart.</li>
1027
996
  <li>Any incoming message triggers the configured action.</li>
1028
- <li>Input message properties are ignored by this node.</li>
997
+ <li>When action is <code>POE controlled by msg.payload</code>, the node reads <code>msg.payload</code>: <code>true</code> enables PoE, <code>false</code> disables PoE.</li>
998
+ <li>For all other actions, input message properties are ignored.</li>
1029
999
  </ul>
1030
1000
 
1031
1001
  <h3>Output</h3>
@@ -49,6 +49,13 @@ function resolveConfiguredAction(value) {
49
49
  const lower = normalized.toLowerCase();
50
50
  const upper = normalized.toUpperCase();
51
51
 
52
+ if (["msgpayload", "payload", "poecontrolledbymsgpayload"].includes(lower)) {
53
+ return {
54
+ type: "poeModeFromPayload",
55
+ payloadAction: "POE_CONTROLLED_BY_MSG_PAYLOAD"
56
+ };
57
+ }
58
+
52
59
  if (["emitpoweratchange", "emit_power_consumption_at_change"].includes(lower)) {
53
60
  return {
54
61
  type: "observePower",
@@ -106,6 +113,35 @@ function resolvePowerIntervalSeconds(value) {
106
113
  return integer;
107
114
  }
108
115
 
116
+ function resolvePayloadBoolean(value) {
117
+ if (typeof value === "boolean") {
118
+ return value;
119
+ }
120
+
121
+ if (typeof value === "number") {
122
+ if (value === 1) {
123
+ return true;
124
+ }
125
+ if (value === 0) {
126
+ return false;
127
+ }
128
+ return null;
129
+ }
130
+
131
+ if (typeof value === "string") {
132
+ const normalized = value.trim().toLowerCase();
133
+ if (["true", "1", "on", "enable", "enabled"].includes(normalized)) {
134
+ return true;
135
+ }
136
+ if (["false", "0", "off", "disable", "disabled"].includes(normalized)) {
137
+ return false;
138
+ }
139
+ return null;
140
+ }
141
+
142
+ return null;
143
+ }
144
+
109
145
  function resolveNodeName(value) {
110
146
  return String(value || "").trim();
111
147
  }
@@ -222,7 +258,7 @@ module.exports = function(RED) {
222
258
  node.deviceId = config.deviceId || "";
223
259
  node.deviceName = resolveDeviceName(config.deviceName);
224
260
  node.portIdx = config.portIdx;
225
- node.action = config.action || "cycle";
261
+ node.action = config.action || "msgPayload";
226
262
  node.powerIntervalSeconds = resolvePowerIntervalSeconds(config.powerIntervalSeconds);
227
263
  node.timeout = Number(config.timeout) > 0 ? Number(config.timeout) : 15000;
228
264
  node.powerPollTimer = null;
@@ -272,6 +308,31 @@ module.exports = function(RED) {
272
308
  return action && action.type === "observePower";
273
309
  }
274
310
 
311
+ function resolvePoeModeActionFromMessage(action, msg) {
312
+ if (!action || action.type !== "poeModeFromPayload") {
313
+ return action;
314
+ }
315
+
316
+ const payload = msg && typeof msg === "object" ? msg.payload : undefined;
317
+ const payloadBoolean = resolvePayloadBoolean(payload);
318
+ if (payloadBoolean === true) {
319
+ return {
320
+ type: "poeMode",
321
+ payloadAction: "ENABLE_POE",
322
+ poeMode: "auto"
323
+ };
324
+ }
325
+ if (payloadBoolean === false) {
326
+ return {
327
+ type: "poeMode",
328
+ payloadAction: "DISABLE_POE",
329
+ poeMode: "off"
330
+ };
331
+ }
332
+
333
+ throw new Error("When action is 'POE controlled by msg.payload', msg.payload must be true/false.");
334
+ }
335
+
275
336
  function formatPowerText(powerW) {
276
337
  const numeric = Number(powerW);
277
338
  if (!Number.isFinite(numeric)) {
@@ -647,13 +708,14 @@ module.exports = function(RED) {
647
708
  }, node.powerIntervalSeconds * 1000);
648
709
  }
649
710
 
650
- async function invoke(send) {
711
+ async function invoke(msg, send) {
651
712
  if (!node.server) {
652
713
  throw new Error("Unifi Network configuration is missing.");
653
714
  }
654
715
 
655
- // The incoming message is only a trigger. The node always executes
656
- // the action configured in the editor.
716
+ // The node executes the action configured in the editor. The only
717
+ // runtime override is the payload-driven action, which maps
718
+ // msg.payload true/false to enable/disable PoE.
657
719
  const deviceId = resolveDeviceId(node.deviceId);
658
720
  if (!deviceId) {
659
721
  throw new Error("Missing switch device id.");
@@ -675,9 +737,11 @@ module.exports = function(RED) {
675
737
  return;
676
738
  }
677
739
 
678
- const result = action.type === "poeMode"
679
- ? await invokePoeMode(deviceId, scoped, portIdx, action)
680
- : await invokePowerCycle(deviceId, scoped, portIdx, action);
740
+ const effectiveAction = resolvePoeModeActionFromMessage(action, msg);
741
+
742
+ const result = effectiveAction.type === "poeMode"
743
+ ? await invokePoeMode(deviceId, scoped, portIdx, effectiveAction)
744
+ : await invokePowerCycle(deviceId, scoped, portIdx, effectiveAction);
681
745
  const powerSnapshot = await fetchSelectedPortSummary(deviceId, portIdx);
682
746
  const selectedPort = powerSnapshot.selectedPort;
683
747
 
@@ -701,19 +765,19 @@ module.exports = function(RED) {
701
765
  selectedPort: selectedPort || undefined
702
766
  }
703
767
  });
704
- decorateOutputMessage(output, output.payload, `request:${action.payloadAction}`);
768
+ decorateOutputMessage(output, output.payload, `request:${effectiveAction.payloadAction}`);
705
769
 
706
- node.status({ fill: "green", shape: "dot", text: `${action.payloadAction} ok` });
770
+ node.status({ fill: "green", shape: "dot", text: `${effectiveAction.payloadAction} ok` });
707
771
  send(output);
708
772
  }
709
773
 
710
- node.on("input", async function(_msg, send, done) {
774
+ node.on("input", async function(msg, send, done) {
711
775
  send = send || function() {
712
776
  node.send.apply(node, arguments);
713
777
  };
714
778
 
715
779
  try {
716
- await invoke(send);
780
+ await invoke(msg, send);
717
781
  if (typeof done === "function") {
718
782
  done();
719
783
  }