node-red-contrib-boolean-logic-ultimate 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@
4
4
  # CHANGELOG
5
5
 
6
6
 
7
+ <p>
8
+ <b>Version 1.2.5</b> January 2026<br/>
9
+ - RailwaySwitchUltimate: configurable output pins (1..10) using Node-RED standard <code>outputs</code> property + migration from legacy <code>outputCount</code> (fixes editor placement issue).<br/>
10
+ - Updated README and examples accordingly.</br>
11
+ </p>
12
+
7
13
  <p>
8
14
  <b>Version 1.2.4</b> January 2026<br/>
9
15
  - Added sample flows in the "example" folder. Just import it via the "import" menu of node-red</br>
package/README.md CHANGED
@@ -468,6 +468,7 @@ The railway switcher, redirect the incoming messages to one ot the avaiable outp
468
468
  | Property | Description |
469
469
  | -------------- | ---------------------------------------------------------------------------------------------------- |
470
470
  | Switcher topic | Whenever the node receives a payload from this **topic**, it redirects the input messages to a choosen output PIN. |
471
+ | Output pins | Number of output pins (outputs) to show. Default is 5, range is 1..10. |
471
472
  | With Input | It's the msg property to be evaluated. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
472
473
  | Translator | Translates the incoming <code>payload</code> value. This allows the compatibility with, for example, **HomeAssistant** nodes. |
473
474
 
@@ -479,7 +480,7 @@ Once an output PIN has been choosen, all messages passing through the node will
479
480
 
480
481
  : topic (string|number) : this is the topic of the switcher message.
481
482
 
482
- : payload (number|boolean) : this is the ouput PIN selector, base 0 (0 is the first output PIN).
483
+ : payload (number|boolean) : this is the ouput PIN selector, base 0 (0 is the first output PIN). Valid range is <code>0..(outputs-1)</code>.
483
484
 
484
485
  ### JSON switcher message
485
486
 
@@ -525,7 +526,7 @@ See the example below.<br/>
525
526
  Copy and paste it into your flow
526
527
 
527
528
  ```javascript
528
- [{"id":"8243309f7c926112","type":"RailwaySwitchUltimate","z":"aa3efc585a6c7b9b","name":"Railway Switch","triggertopic":"switcher","initializewith":"3","payloadPropName":"payload","translatorConfig":"","x":350,"y":260,"wires":[["7f5a2c19a9ef64c8"],["5a35a650b225d910"],[],[],[]]},{"id":"d7bbc077bc20f4ea","type":"InjectUltimate","z":"aa3efc585a6c7b9b","name":"Junction switcher to Rail 0","topic":"","curVal":true,"outputJSON":"{ \n\t\"payload\":0,\n\t\"topic\":\"switcher\"\n}","x":350,"y":80,"wires":[[],[],[],["8243309f7c926112"]]},{"id":"5656d0c2ba66ed5e","type":"InjectUltimate","z":"aa3efc585a6c7b9b","name":"Junction switcher to Rail 1","topic":"","curVal":true,"outputJSON":"{ \n\t\"payload\":\"1\",\n\t\"topic\":\"switcher\"\n}","x":350,"y":160,"wires":[[],[],[],["8243309f7c926112"]]},{"id":"2253336fa8374c78","type":"InjectUltimate","z":"aa3efc585a6c7b9b","name":"Train","topic":"","curVal":true,"outputJSON":"{ \n\t\"payload\":\"hello\",\n\t\"topic\":\"I'm a train!\"\n}","x":110,"y":280,"wires":[["8243309f7c926112"],[],[],[]]},{"id":"7f5a2c19a9ef64c8","type":"debug","z":"aa3efc585a6c7b9b","name":"Rail 0","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":590,"y":260,"wires":[]},{"id":"5a35a650b225d910","type":"debug","z":"aa3efc585a6c7b9b","name":"Rail 1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":590,"y":300,"wires":[]}]
529
+ [{"id":"8243309f7c926112","type":"RailwaySwitchUltimate","z":"aa3efc585a6c7b9b","name":"Railway Switch","triggertopic":"switcher","outputs":5,"initializewith":"3","payloadPropName":"payload","translatorConfig":"","x":350,"y":260,"wires":[["7f5a2c19a9ef64c8"],["5a35a650b225d910"],[],[],[]]},{"id":"d7bbc077bc20f4ea","type":"InjectUltimate","z":"aa3efc585a6c7b9b","name":"Junction switcher to Rail 0","topic":"","curVal":true,"outputJSON":"{ \n\t\"payload\":0,\n\t\"topic\":\"switcher\"\n}","x":350,"y":80,"wires":[[],[],[],["8243309f7c926112"]]},{"id":"5656d0c2ba66ed5e","type":"InjectUltimate","z":"aa3efc585a6c7b9b","name":"Junction switcher to Rail 1","topic":"","curVal":true,"outputJSON":"{ \n\t\"payload\":\"1\",\n\t\"topic\":\"switcher\"\n}","x":350,"y":160,"wires":[[],[],[],["8243309f7c926112"]]},{"id":"2253336fa8374c78","type":"InjectUltimate","z":"aa3efc585a6c7b9b","name":"Train","topic":"","curVal":true,"outputJSON":"{ \n\t\"payload\":\"hello\",\n\t\"topic\":\"I'm a train!\"\n}","x":110,"y":280,"wires":[["8243309f7c926112"],[],[],[]]},{"id":"7f5a2c19a9ef64c8","type":"debug","z":"aa3efc585a6c7b9b","name":"Rail 0","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":590,"y":260,"wires":[]},{"id":"5a35a650b225d910","type":"debug","z":"aa3efc585a6c7b9b","name":"Rail 1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":590,"y":300,"wires":[]}]
529
530
  ```
530
531
 
531
532
  <br/>
@@ -5,6 +5,8 @@
5
5
  defaults: {
6
6
  name: { value: "Railway Switch" },
7
7
  triggertopic: { value: "switcher" },
8
+ outputs: { value: 5 },
9
+ outputCount: { value: 5 }, // legacy (pre-outputs property) kept for backward compatibility
8
10
  initializewith: { value: "1" },
9
11
  payloadPropName: { value: "payload", required: false },
10
12
  translatorConfig: { type: "translator-config", required: false }
@@ -22,9 +24,87 @@
22
24
  paletteLabel: function () {
23
25
  return "Railway Switch";
24
26
  },
27
+ onadd: function () {
28
+ // Prefer the saved `wires.length` (it reflects the node's output count in the flow),
29
+ // otherwise fall back to legacy `outputCount`, then default to 5.
30
+ function clampOutputs(raw) {
31
+ var value = parseInt(raw, 10);
32
+ if (isNaN(value)) value = 5;
33
+ value = Math.max(1, Math.min(10, value));
34
+ return value;
35
+ }
36
+
37
+ var wiresCount = Array.isArray(this.wires) ? this.wires.length : NaN;
38
+ if (!isNaN(wiresCount) && wiresCount >= 1) {
39
+ this.outputs = clampOutputs(wiresCount);
40
+ this.outputCount = this.outputs; // keep legacy aligned
41
+ return;
42
+ }
43
+
44
+ var legacy = parseInt(this.outputCount, 10);
45
+ if (!isNaN(legacy)) {
46
+ this.outputs = clampOutputs(legacy);
47
+ this.outputCount = this.outputs;
48
+ }
49
+ },
25
50
  oneditprepare: function () {
26
51
  if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
27
52
  $("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
53
+
54
+ function rebuildPinSelect(outputCount) {
55
+ const $select = $("#node-input-initializewith");
56
+ const previous = $select.val();
57
+ $select.empty();
58
+ for (let i = 0; i < outputCount; i += 1) {
59
+ $("<option></option>").val(String(i)).text("PIN " + i).appendTo($select);
60
+ }
61
+ let nextValue = previous;
62
+ if (nextValue === undefined || nextValue === null || nextValue === "" || parseInt(nextValue, 10) >= outputCount) {
63
+ nextValue = "0";
64
+ }
65
+ $select.val(nextValue);
66
+ }
67
+
68
+ function clampOutputs(raw) {
69
+ var value = parseInt(raw, 10);
70
+ if (isNaN(value)) value = 5;
71
+ value = Math.max(1, Math.min(10, value));
72
+ return value;
73
+ }
74
+
75
+ // Migration: prefer saved wires length, then legacy outputCount, then current outputs.
76
+ var outputs = clampOutputs($("#node-input-outputs").val());
77
+ var wiresCount = Array.isArray(this.wires) ? this.wires.length : NaN;
78
+ if (!isNaN(wiresCount) && wiresCount >= 1 && wiresCount <= 10) {
79
+ outputs = clampOutputs(wiresCount);
80
+ } else {
81
+ var legacy = parseInt(this.outputCount, 10);
82
+ if (!isNaN(legacy) && legacy >= 1 && legacy <= 10 && outputs === 5 && legacy !== 5) {
83
+ outputs = legacy;
84
+ }
85
+ }
86
+ $("#node-input-outputs").val(String(outputs));
87
+ rebuildPinSelect(outputs);
88
+
89
+ $("#node-input-outputs").on("change", function () {
90
+ var nextOutputs = clampOutputs($(this).val());
91
+ $(this).val(String(nextOutputs));
92
+ rebuildPinSelect(nextOutputs);
93
+ });
94
+ },
95
+ oneditsave: function () {
96
+ var value = parseInt($("#node-input-outputs").val(), 10);
97
+ if (isNaN(value)) value = 5;
98
+ value = Math.max(1, Math.min(10, value));
99
+ this.outputs = value;
100
+ this.outputCount = value; // keep legacy field aligned for backward compatibility
101
+
102
+ var init = parseInt($("#node-input-initializewith").val(), 10);
103
+ if (isNaN(init) || init < 0 || init >= value) {
104
+ this.initializewith = "0";
105
+ } else {
106
+ this.initializewith = String(init);
107
+ }
28
108
  }
29
109
  });
30
110
  </script>
@@ -41,23 +121,32 @@
41
121
  <input type="text" id="node-input-name" placeholder="Name">
42
122
  </div>
43
123
 
44
- <div class="form-row">
124
+ <div class="form-row">
45
125
  <label for="node-input-triggertopic"><i class="icon-tag"></i> Switcher topic</label>
46
126
  <input type="text" id="node-input-triggertopic" placeholder="Name">
47
127
  </div>
128
+ <div class="form-row">
129
+ <label style="width:160px" for="node-input-outputs"><i class="fa fa-circle-o-notch"></i> Output pins</label>
130
+ <select type="text" id="node-input-outputs" style="width:250px">
131
+ <option value="1">1</option>
132
+ <option value="2">2</option>
133
+ <option value="3">3</option>
134
+ <option value="4">4</option>
135
+ <option value="5">5</option>
136
+ <option value="6">6</option>
137
+ <option value="7">7</option>
138
+ <option value="8">8</option>
139
+ <option value="9">9</option>
140
+ <option value="10">10</option>
141
+ </select>
142
+ </div>
48
143
  <div class="form-row">
49
144
  <label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> With Input</label>
50
145
  <input type="text" id="node-input-payloadPropName">
51
146
  </div>
52
147
  <div class="form-row">
53
148
  <label style="width:160px" for="node-input-initializewith"><i class="fa fa-home"></i> At node-red start</label>
54
- <select type="text" id="node-input-initializewith" placeholder="" style="width:250px">
55
- <option value="0">PIN 0</option>
56
- <option value="1">PIN 1</option>
57
- <option value="2">PIN 2</option>
58
- <option value="3">PIN 3</option>
59
- <option value="4">PIN 4</option>
60
- </select>
149
+ <select type="text" id="node-input-initializewith" placeholder="" style="width:250px"></select>
61
150
  </div>
62
151
  <div class="form-row">
63
152
  <label for="node-input-translatorConfig">
@@ -73,6 +162,7 @@
73
162
  |Property|Description|
74
163
  |--|--|
75
164
  | Switcher topic | Whenever the node receives a payload from this **topic**, it redirects the input messages to a choosen output PIN. |
165
+ | Output pins | Number of output pins to display (1..10). |
76
166
  | With Input | It's the msg property to be evaluated. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
77
167
  | Translator | Translates the incoming <code>payload</code> value. This allows the compatibility with, for example, **HomeAssistant** nodes. |
78
168
 
@@ -82,7 +172,7 @@ The *Switcher topic* controls where the railway switch must be switched, between
82
172
  Once an output PIN has been choosen, all messages passing through the node will be deviated to te choosen output PIN.
83
173
 
84
174
  : topic (string|number) : this is the topic of the switcher message.
85
- : payload (number|boolean) : this is the ouput PIN selector, base 0 (0 is the first output PIN).
175
+ : payload (number|boolean) : this is the output PIN selector, base 0 (0 is the first output PIN). Valid range is <code>0..(output pins-1)</code>.
86
176
 
87
177
  ### JSON switcher message
88
178
 
@@ -122,4 +212,4 @@ this JSON input message redirects all input messages to the third PIN, and so on
122
212
 
123
213
  [Find it useful?](https://www.paypal.me/techtoday)
124
214
 
125
- </script>
215
+ </script>
@@ -4,12 +4,31 @@ module.exports = function (RED) {
4
4
  this.config = config;
5
5
  var node = this;
6
6
  node.currentMsg = {}; // Stores current payload
7
+
8
+ const outputCountRaw =
9
+ config.outputs !== undefined ? parseInt(config.outputs, 10) : parseInt(config.outputCount, 10);
10
+ node.outputCount = Number.isFinite(outputCountRaw)
11
+ ? Math.max(1, Math.min(10, outputCountRaw))
12
+ : 5;
13
+
7
14
  node.sTriggerTopic =
8
15
  node.config.triggertopic.replace(
9
16
  /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,
10
17
  ""
11
18
  ) || "trigger"; // Topic controlling the sRailway
12
- node.sRailway = String(node.config.initializewith); // Railway selector
19
+
20
+ function parsePinIndex(value) {
21
+ if (value === false) return 0;
22
+ if (value === true) return 1;
23
+ const parsed = parseInt(String(value), 10);
24
+ return Number.isFinite(parsed) ? parsed : null;
25
+ }
26
+
27
+ const initialPin = parsePinIndex(node.config.initializewith);
28
+ node.railIndex =
29
+ initialPin === null
30
+ ? 0
31
+ : Math.max(0, Math.min(node.outputCount - 1, initialPin)); // Railway selector
13
32
 
14
33
  function setNodeStatus({ fill, shape, text }) {
15
34
  let dDate = new Date();
@@ -30,7 +49,7 @@ module.exports = function (RED) {
30
49
  setNodeStatus({
31
50
  fill: "green",
32
51
  shape: "dot",
33
- text: "-> PIN " + node.sRailway,
52
+ text: "-> PIN " + node.railIndex,
34
53
  });
35
54
 
36
55
  };
@@ -67,7 +86,7 @@ module.exports = function (RED) {
67
86
  setNodeStatus({
68
87
  fill: "red",
69
88
  shape: "dot",
70
- text: "Received invalid payload from " + msg.topic || "",
89
+ text: "Received invalid payload from " + (msg.topic || ""),
71
90
  });
72
91
  return;
73
92
  }
@@ -78,17 +97,31 @@ module.exports = function (RED) {
78
97
  );
79
98
  if (msg.payload === undefined) return null;
80
99
 
81
- node.sRailway = msg.payload;
100
+ const nextPin = parsePinIndex(msg.payload);
101
+ if (nextPin === null || nextPin < 0 || nextPin >= node.outputCount) {
102
+ setNodeStatus({
103
+ fill: "red",
104
+ shape: "dot",
105
+ text:
106
+ "Invalid PIN " +
107
+ String(msg.payload) +
108
+ " (valid 0.." +
109
+ String(node.outputCount - 1) +
110
+ ")",
111
+ });
112
+ return;
113
+ }
114
+
115
+ node.railIndex = nextPin;
82
116
  node.alignStatus();
83
117
  return; // DONT'S SEND THIS MESSAGE
84
118
  }
85
119
  }
86
120
  node.currentMsg = RED.util.cloneMessage(msg);
87
- if (node.sRailway === "0") node.send([msg, null, null, null, null]);
88
- if (node.sRailway === "1") node.send([null, msg, null, null, null]);
89
- if (node.sRailway === "2") node.send([null, null, msg, null, null]);
90
- if (node.sRailway === "3") node.send([null, null, null, msg, null]);
91
- if (node.sRailway === "4") node.send([null, null, null, null, msg]);
121
+
122
+ const out = new Array(node.outputCount).fill(null);
123
+ out[node.railIndex] = msg;
124
+ node.send(out);
92
125
  });
93
126
  }
94
127
 
@@ -10,8 +10,8 @@
10
10
  "id": "rws_cmt_1",
11
11
  "type": "comment",
12
12
  "z": "rws_tab_1",
13
- "name": "Switcher topic: switcher (payload 0..4)",
14
- "info": "1) Invia switcher=0/1/2 per selezionare l'uscita.\n2) Invia DATA e osserva su quale debug arriva.",
13
+ "name": "Switcher topic: switcher (payload 0..N-1)",
14
+ "info": "1) Imposta i pin di uscita nel nodo (Output pins).\n2) Invia switcher=0/1/2 per selezionare l'uscita.\n3) Invia DATA e osserva su quale debug arriva.",
15
15
  "x": 280,
16
16
  "y": 60,
17
17
  "wires": []
@@ -90,6 +90,7 @@
90
90
  "z": "rws_tab_1",
91
91
  "name": "Railway Switch",
92
92
  "triggertopic": "switcher",
93
+ "outputs": 5,
93
94
  "initializewith": "1",
94
95
  "payloadPropName": "payload",
95
96
  "translatorConfig": "",
@@ -183,4 +184,3 @@
183
184
  "wires": []
184
185
  }
185
186
  ]
186
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-boolean-logic-ultimate",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "A set of Node-RED enhanced boolean logic and utility nodes, flow interruption, blinker, invert, filter, toggle etc.., with persistent values after reboot. Compatible also with Homeassistant values.",
5
5
  "author": "Supergiovane (https://github.com/Supergiovane)",
6
6
  "dependencies": {
@@ -51,4 +51,4 @@
51
51
  "scripts": {
52
52
  "test": "mocha test/**/*.spec.js"
53
53
  }
54
- }
54
+ }
package/test/helpers.js CHANGED
@@ -8,10 +8,25 @@ helper.init(require.resolve('node-red')); // initialise with Node-RED runtime
8
8
  const nodes = {
9
9
  RateLimiterUltimate: require(path.join('..', 'boolean-logic-ultimate', 'RateLimiterUltimate.js')),
10
10
  PresenceSimulatorUltimate: require(path.join('..', 'boolean-logic-ultimate', 'PresenceSimulatorUltimate.js')),
11
+ RailwaySwitchUltimate: require(path.join('..', 'boolean-logic-ultimate', 'RailwaySwitchUltimate.js')),
11
12
  };
12
13
 
13
14
  function loadNode(nodeDef, flow, credentials = {}) {
14
- return helper.load(nodeDef, flow, credentials);
15
+ const normalizedFlow = flow.map((node, index) => {
16
+ if (
17
+ node &&
18
+ node.type &&
19
+ node.type !== 'tab' &&
20
+ node.type !== 'subflow' &&
21
+ node.type !== 'group' &&
22
+ node.z &&
23
+ !(Object.prototype.hasOwnProperty.call(node, 'x') && Object.prototype.hasOwnProperty.call(node, 'y'))
24
+ ) {
25
+ return { ...node, x: 100 + index * 10, y: 100 + index * 10 };
26
+ }
27
+ return node;
28
+ });
29
+ return helper.load(nodeDef, normalizedFlow, credentials);
15
30
  }
16
31
 
17
32
  function loadRateLimiter(flow, credentials = {}) {
@@ -22,8 +37,13 @@ function loadPresence(flow, credentials = {}) {
22
37
  return loadNode(nodes.PresenceSimulatorUltimate, flow, credentials);
23
38
  }
24
39
 
40
+ function loadRailwaySwitch(flow, credentials = {}) {
41
+ return loadNode(nodes.RailwaySwitchUltimate, flow, credentials);
42
+ }
43
+
25
44
  module.exports = {
26
45
  helper,
27
46
  loadRateLimiter,
28
47
  loadPresence,
48
+ loadRailwaySwitch,
29
49
  };
@@ -39,7 +39,7 @@ describe('PresenceSimulatorUltimate node', function () {
39
39
  ];
40
40
 
41
41
  loadPresence(flow).then(() => {
42
- const input = helper.getNode('in');
42
+ const presence = helper.getNode('presence');
43
43
  const out = helper.getNode('out');
44
44
 
45
45
  out.on('input', (msg) => {
@@ -52,7 +52,7 @@ describe('PresenceSimulatorUltimate node', function () {
52
52
  }
53
53
  });
54
54
 
55
- input.receive({ topic: 'presence', command: 'start' });
55
+ presence.receive({ topic: 'presence', command: 'start' });
56
56
  }).catch(done);
57
57
  });
58
58
 
@@ -76,14 +76,14 @@ describe('PresenceSimulatorUltimate node', function () {
76
76
  ];
77
77
 
78
78
  loadPresence(flow).then(() => {
79
- const input = helper.getNode('in');
79
+ const presence = helper.getNode('presence');
80
80
  const out = helper.getNode('out');
81
81
  let received = 0;
82
82
 
83
83
  out.on('input', () => {
84
84
  received += 1;
85
85
  if (received === 1) {
86
- input.receive({ topic: 'presence', command: 'stop' });
86
+ presence.receive({ topic: 'presence', command: 'stop' });
87
87
  setTimeout(() => {
88
88
  try {
89
89
  expect(received).to.equal(1);
@@ -95,7 +95,7 @@ describe('PresenceSimulatorUltimate node', function () {
95
95
  }
96
96
  });
97
97
 
98
- input.receive({ topic: 'presence', command: 'start' });
98
+ presence.receive({ topic: 'presence', command: 'start' });
99
99
  }).catch(done);
100
100
  });
101
101
  });
@@ -0,0 +1,251 @@
1
+ 'use strict';
2
+
3
+ const { expect } = require('chai');
4
+ const { helper, loadRailwaySwitch } = require('./helpers');
5
+
6
+ describe('RailwaySwitchUltimate node', function () {
7
+ this.timeout(5000);
8
+
9
+ before(function (done) {
10
+ helper.startServer(done);
11
+ });
12
+
13
+ after(function (done) {
14
+ helper.stopServer(done);
15
+ });
16
+
17
+ afterEach(function () {
18
+ return helper.unload();
19
+ });
20
+
21
+ it('routes messages to the selected output pin', function (done) {
22
+ const flowId = 'flow-rws-1';
23
+ const flow = [
24
+ { id: flowId, type: 'tab', label: 'flow-rws-1' },
25
+ {
26
+ id: 'rws',
27
+ type: 'RailwaySwitchUltimate',
28
+ z: flowId,
29
+ name: 'rws',
30
+ triggertopic: 'switcher',
31
+ outputs: 5,
32
+ initializewith: '0',
33
+ payloadPropName: 'payload',
34
+ translatorConfig: '',
35
+ wires: [['out0'], ['out1'], ['out2'], ['out3'], ['out4']],
36
+ },
37
+ { id: 'in', type: 'helper', z: flowId, wires: [['rws']] },
38
+ { id: 'out0', type: 'helper', z: flowId },
39
+ { id: 'out1', type: 'helper', z: flowId },
40
+ { id: 'out2', type: 'helper', z: flowId },
41
+ { id: 'out3', type: 'helper', z: flowId },
42
+ { id: 'out4', type: 'helper', z: flowId },
43
+ ];
44
+
45
+ loadRailwaySwitch(flow).then(() => {
46
+ const rws = helper.getNode('rws');
47
+ const out0 = helper.getNode('out0');
48
+ const out1 = helper.getNode('out1');
49
+ const out2 = helper.getNode('out2');
50
+ const out3 = helper.getNode('out3');
51
+ const out4 = helper.getNode('out4');
52
+
53
+ const received = { out0: [], out1: [], out2: [], out3: [], out4: [] };
54
+ out0.on('input', (msg) => received.out0.push(msg));
55
+ out1.on('input', (msg) => received.out1.push(msg));
56
+ out2.on('input', (msg) => received.out2.push(msg));
57
+ out3.on('input', (msg) => received.out3.push(msg));
58
+ out4.on('input', (msg) => received.out4.push(msg));
59
+
60
+ rws.receive({ topic: 'switcher', payload: 2 });
61
+ rws.receive({ topic: 'data', payload: 'train' });
62
+
63
+ setTimeout(() => {
64
+ try {
65
+ expect(received.out0).to.have.length(0);
66
+ expect(received.out1).to.have.length(0);
67
+ expect(received.out3).to.have.length(0);
68
+ expect(received.out4).to.have.length(0);
69
+ expect(received.out2).to.have.length(1);
70
+ expect(received.out2[0]).to.include({ topic: 'data', payload: 'train' });
71
+ done();
72
+ } catch (err) {
73
+ done(err);
74
+ }
75
+ }, 50);
76
+ }).catch(done);
77
+ });
78
+
79
+ it('ignores an out-of-range selector and keeps the current pin', function (done) {
80
+ const flowId = 'flow-rws-2';
81
+ const flow = [
82
+ { id: flowId, type: 'tab', label: 'flow-rws-2' },
83
+ {
84
+ id: 'rws',
85
+ type: 'RailwaySwitchUltimate',
86
+ z: flowId,
87
+ name: 'rws',
88
+ triggertopic: 'switcher',
89
+ outputs: 5,
90
+ initializewith: '1',
91
+ payloadPropName: 'payload',
92
+ translatorConfig: '',
93
+ wires: [['out0'], ['out1'], ['out2'], ['out3'], ['out4']],
94
+ },
95
+ { id: 'in', type: 'helper', z: flowId, wires: [['rws']] },
96
+ { id: 'out0', type: 'helper', z: flowId },
97
+ { id: 'out1', type: 'helper', z: flowId },
98
+ { id: 'out2', type: 'helper', z: flowId },
99
+ { id: 'out3', type: 'helper', z: flowId },
100
+ { id: 'out4', type: 'helper', z: flowId },
101
+ ];
102
+
103
+ loadRailwaySwitch(flow).then(() => {
104
+ const rws = helper.getNode('rws');
105
+ const out0 = helper.getNode('out0');
106
+ const out1 = helper.getNode('out1');
107
+ const out2 = helper.getNode('out2');
108
+ const out3 = helper.getNode('out3');
109
+ const out4 = helper.getNode('out4');
110
+
111
+ const received = { out0: [], out1: [], out2: [], out3: [], out4: [] };
112
+ out0.on('input', (msg) => received.out0.push(msg));
113
+ out1.on('input', (msg) => received.out1.push(msg));
114
+ out2.on('input', (msg) => received.out2.push(msg));
115
+ out3.on('input', (msg) => received.out3.push(msg));
116
+ out4.on('input', (msg) => received.out4.push(msg));
117
+
118
+ rws.receive({ topic: 'switcher', payload: 9 }); // out of range
119
+ rws.receive({ topic: 'data', payload: 'train' });
120
+
121
+ setTimeout(() => {
122
+ try {
123
+ expect(received.out0).to.have.length(0);
124
+ expect(received.out2).to.have.length(0);
125
+ expect(received.out3).to.have.length(0);
126
+ expect(received.out4).to.have.length(0);
127
+ expect(received.out1).to.have.length(1);
128
+ expect(received.out1[0]).to.include({ topic: 'data', payload: 'train' });
129
+ done();
130
+ } catch (err) {
131
+ done(err);
132
+ }
133
+ }, 50);
134
+ }).catch(done);
135
+ });
136
+
137
+ it('is backward compatible when outputCount is missing (defaults to 5)', function (done) {
138
+ const flowId = 'flow-rws-3';
139
+ const flow = [
140
+ { id: flowId, type: 'tab', label: 'flow-rws-3' },
141
+ {
142
+ id: 'rws',
143
+ type: 'RailwaySwitchUltimate',
144
+ z: flowId,
145
+ name: 'rws',
146
+ triggertopic: 'switcher',
147
+ initializewith: '4',
148
+ payloadPropName: 'payload',
149
+ translatorConfig: '',
150
+ wires: [['out0'], ['out1'], ['out2'], ['out3'], ['out4']],
151
+ },
152
+ { id: 'out0', type: 'helper', z: flowId },
153
+ { id: 'out1', type: 'helper', z: flowId },
154
+ { id: 'out2', type: 'helper', z: flowId },
155
+ { id: 'out3', type: 'helper', z: flowId },
156
+ { id: 'out4', type: 'helper', z: flowId },
157
+ ];
158
+
159
+ loadRailwaySwitch(flow).then(() => {
160
+ const rws = helper.getNode('rws');
161
+ const out4 = helper.getNode('out4');
162
+
163
+ out4.on('input', (msg) => {
164
+ try {
165
+ expect(msg).to.include({ topic: 'data', payload: 'train' });
166
+ done();
167
+ } catch (err) {
168
+ done(err);
169
+ }
170
+ });
171
+
172
+ rws.receive({ topic: 'data', payload: 'train' });
173
+ }).catch(done);
174
+ });
175
+
176
+ it('supports configuring outputs to 1', function (done) {
177
+ const flowId = 'flow-rws-4';
178
+ const flow = [
179
+ { id: flowId, type: 'tab', label: 'flow-rws-4' },
180
+ {
181
+ id: 'rws',
182
+ type: 'RailwaySwitchUltimate',
183
+ z: flowId,
184
+ name: 'rws',
185
+ triggertopic: 'switcher',
186
+ outputs: 1,
187
+ initializewith: '0',
188
+ payloadPropName: 'payload',
189
+ translatorConfig: '',
190
+ wires: [['out0']],
191
+ },
192
+ { id: 'out0', type: 'helper', z: flowId },
193
+ ];
194
+
195
+ loadRailwaySwitch(flow).then(() => {
196
+ const rws = helper.getNode('rws');
197
+ const out0 = helper.getNode('out0');
198
+
199
+ out0.on('input', (msg) => {
200
+ try {
201
+ expect(msg).to.include({ topic: 'data', payload: 'train' });
202
+ done();
203
+ } catch (err) {
204
+ done(err);
205
+ }
206
+ });
207
+
208
+ rws.receive({ topic: 'switcher', payload: 1 }); // out of range for outputs=1
209
+ rws.receive({ topic: 'data', payload: 'train' });
210
+ }).catch(done);
211
+ });
212
+
213
+ it('is backward compatible with legacy outputCount when outputs is missing', function (done) {
214
+ const flowId = 'flow-rws-5';
215
+ const flow = [
216
+ { id: flowId, type: 'tab', label: 'flow-rws-5' },
217
+ {
218
+ id: 'rws',
219
+ type: 'RailwaySwitchUltimate',
220
+ z: flowId,
221
+ name: 'rws',
222
+ triggertopic: 'switcher',
223
+ outputCount: 3,
224
+ initializewith: '0',
225
+ payloadPropName: 'payload',
226
+ translatorConfig: '',
227
+ wires: [['out0'], ['out1'], ['out2']],
228
+ },
229
+ { id: 'out0', type: 'helper', z: flowId },
230
+ { id: 'out1', type: 'helper', z: flowId },
231
+ { id: 'out2', type: 'helper', z: flowId },
232
+ ];
233
+
234
+ loadRailwaySwitch(flow).then(() => {
235
+ const rws = helper.getNode('rws');
236
+ const out2 = helper.getNode('out2');
237
+
238
+ out2.on('input', (msg) => {
239
+ try {
240
+ expect(msg).to.include({ topic: 'data', payload: 'train' });
241
+ done();
242
+ } catch (err) {
243
+ done(err);
244
+ }
245
+ });
246
+
247
+ rws.receive({ topic: 'switcher', payload: 2 });
248
+ rws.receive({ topic: 'data', payload: 'train' });
249
+ }).catch(done);
250
+ });
251
+ });
@@ -41,7 +41,7 @@ describe('RateLimiterUltimate node', function () {
41
41
  ];
42
42
 
43
43
  loadRateLimiter(flow).then(() => {
44
- const input = helper.getNode('in');
44
+ const rate = helper.getNode('rate');
45
45
  const out = helper.getNode('out');
46
46
  const diag = helper.getNode('diag');
47
47
 
@@ -56,7 +56,7 @@ describe('RateLimiterUltimate node', function () {
56
56
  }
57
57
  });
58
58
 
59
- input.receive({ topic: 'sensor', payload: 'first' });
59
+ rate.receive({ topic: 'sensor', payload: 'first' });
60
60
  }).catch(done);
61
61
  });
62
62
 
@@ -83,7 +83,7 @@ describe('RateLimiterUltimate node', function () {
83
83
  ];
84
84
 
85
85
  loadRateLimiter(flow).then(() => {
86
- const input = helper.getNode('in');
86
+ const rate = helper.getNode('rate');
87
87
  const out = helper.getNode('out');
88
88
  const diag = helper.getNode('diag');
89
89
  let seenForward = 0;
@@ -107,9 +107,9 @@ describe('RateLimiterUltimate node', function () {
107
107
  }
108
108
  });
109
109
 
110
- input.receive({ topic: 'sensor', payload: 'first' });
110
+ rate.receive({ topic: 'sensor', payload: 'first' });
111
111
  setTimeout(() => {
112
- input.receive({ topic: 'sensor', payload: 'second' });
112
+ rate.receive({ topic: 'sensor', payload: 'second' });
113
113
  }, 20);
114
114
  }).catch(done);
115
115
  });
@@ -138,7 +138,7 @@ describe('RateLimiterUltimate node', function () {
138
138
  ];
139
139
 
140
140
  loadRateLimiter(flow).then(() => {
141
- const input = helper.getNode('in');
141
+ const rate = helper.getNode('rate');
142
142
  const out = helper.getNode('out');
143
143
  const diag = helper.getNode('diag');
144
144
  const start = Date.now();
@@ -160,9 +160,9 @@ describe('RateLimiterUltimate node', function () {
160
160
  }
161
161
  });
162
162
 
163
- input.receive({ topic: 'sensor', payload: 'one' });
163
+ rate.receive({ topic: 'sensor', payload: 'one' });
164
164
  setTimeout(() => {
165
- input.receive({ topic: 'sensor', payload: 'two' });
165
+ rate.receive({ topic: 'sensor', payload: 'two' });
166
166
  }, 20);
167
167
  }).catch(done);
168
168
  });
@@ -6,7 +6,21 @@ const { helper } = require('./helpers');
6
6
  const staircaseNode = require('../boolean-logic-ultimate/StaircaseLightUltimate.js');
7
7
 
8
8
  function loadStaircase(flow, credentials) {
9
- return helper.load(staircaseNode, flow, credentials || {});
9
+ const normalizedFlow = flow.map((node, index) => {
10
+ if (
11
+ node &&
12
+ node.type &&
13
+ node.type !== 'tab' &&
14
+ node.type !== 'subflow' &&
15
+ node.type !== 'group' &&
16
+ node.z &&
17
+ !(Object.prototype.hasOwnProperty.call(node, 'x') && Object.prototype.hasOwnProperty.call(node, 'y'))
18
+ ) {
19
+ return { ...node, x: 100 + index * 10, y: 100 + index * 10 };
20
+ }
21
+ return node;
22
+ });
23
+ return helper.load(staircaseNode, normalizedFlow, credentials || {});
10
24
  }
11
25
 
12
26
  describe('StaircaseLightUltimate node', function () {
@@ -52,7 +66,7 @@ describe('StaircaseLightUltimate node', function () {
52
66
  ];
53
67
 
54
68
  loadStaircase(flow).then(() => {
55
- const input = helper.getNode('in');
69
+ const stair = helper.getNode('stair');
56
70
  const outOn = helper.getNode('outOn');
57
71
  const outWarn = helper.getNode('outWarn');
58
72
  const events = [];
@@ -76,7 +90,7 @@ describe('StaircaseLightUltimate node', function () {
76
90
  }
77
91
  }, 400);
78
92
 
79
- input.receive({ payload: true });
93
+ stair.receive({ payload: true });
80
94
  }).catch(done);
81
95
  });
82
96
 
@@ -105,8 +119,7 @@ describe('StaircaseLightUltimate node', function () {
105
119
  ];
106
120
 
107
121
  loadStaircase(flow).then(() => {
108
- const input = helper.getNode('in');
109
- const control = helper.getNode('control');
122
+ const stair = helper.getNode('stair');
110
123
  const out = helper.getNode('out');
111
124
  const events = [];
112
125
 
@@ -114,10 +127,10 @@ describe('StaircaseLightUltimate node', function () {
114
127
  events.push({ type: msg.event, at: Date.now() });
115
128
  });
116
129
 
117
- input.receive({ payload: true });
130
+ stair.receive({ payload: true });
118
131
 
119
132
  setTimeout(() => {
120
- control.receive({ topic: 'stairs', command: 'extend' });
133
+ stair.receive({ topic: 'stairs', command: 'extend' });
121
134
  }, 80);
122
135
 
123
136
  setTimeout(() => {