node-red-contrib-boolean-logic-ultimate 1.1.5 → 1.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
 
4
4
  # CHANGELOG
5
5
 
6
+ <p>
7
+ <b>Version 1.1.7</b> April 2024<br/>
8
+ - Math node: <b>BREAKING CHANGE</b>: in SUBTRACT mode, now you must set a msg.topic to start subtracting from.</br>
9
+ </p>
6
10
  <p>
7
11
  <b>Version 1.1.5</b> April 2024<br/>
8
12
  - Math node: fixed an issue with the "subtract" operator. See contestual help in the node-red help tab.</br>
@@ -11,8 +11,8 @@
11
11
  },
12
12
  math: {
13
13
  value: "sum"
14
- }
15
-
14
+ },
15
+ subtractstartfrom: { value: "" }
16
16
  },
17
17
  inputs: 1,
18
18
  outputs: 1,
@@ -27,6 +27,13 @@
27
27
  oneditprepare: function () {
28
28
  if ($("#node-input-property").val() === "") $("#node-input-property").val("payload");
29
29
  $("#node-input-property").typedInput({ default: 'msg', types: ['msg'] });
30
+ $("#node-input-math").on('change', function () {
31
+ if ($("#node-input-math").val() === "subtract") {
32
+ $("#divSubtractFirst").show()
33
+ } else {
34
+ $("#divSubtractFirst").hide()
35
+ }
36
+ })
30
37
  }
31
38
  });
32
39
  </script>
@@ -54,15 +61,20 @@
54
61
  <option value="subtract">Subtract</option>
55
62
  </select>
56
63
  </div>
64
+ <div class="form-row" id="divSubtractFirst" hidden>
65
+ <label for="node-input-subtractstartfrom"><i class="icon-tag"></i> Subtract from</label>
66
+ <input type="text" id="node-input-subtractstartfrom" placeholder="Type the msg.topic. See the help.">
67
+ </div>
57
68
  </script>
58
69
 
59
70
  <script type="text/markdown" data-help-name="SumUltimate">
60
- <p>The pourpose of this node is to do maths on the incoming values. Each incoming message MUST HAVE OWN TOPIC.</p>
71
+ <p>The pourpose of this node is to do maths on the incoming values. Each incoming message MUST HAVE OWN TOPIC, that means, each inbound **msg.topic** must be **different**.</p>
61
72
 
62
73
  |Property|Description|
63
74
  |--|--|
64
75
  | 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"* |
65
- | Operation | Operation to be performed. For **subtract** operation, the **first topic** arriving to the node is the number to subtract to.|
76
+ | Operation | Operation to be performed. |
77
+ | Subtract from | Only visible when the *operation* is **subtract**. The *msg.topic* indicating the start number for subtraction. This can be, for example, ***SolarPower***, indicating the power from wich you could subtract the house power consumption and obtain the power you sell to the grid. Remember, each inbound msg.topic to be subtracted must be different.|
66
78
 
67
79
  <br/>
68
80
  <br/>
@@ -4,6 +4,7 @@ module.exports = function (RED) {
4
4
  this.config = config;
5
5
  var node = this;
6
6
  node.math = config.math === undefined ? "sum" : config.math;
7
+ node.subtractstartfrom = config.subtractstartfrom === undefined ? "" : config.subtractstartfrom;
7
8
  node.topics = [];
8
9
 
9
10
  function setNodeStatus({ fill, shape, text }) {
@@ -50,8 +51,11 @@ module.exports = function (RED) {
50
51
 
51
52
  // Sum
52
53
  if (!isNaN(ret) && isFinite(ret)) {
53
- if (node.topics.find(a => a.id === msg.topic.toString()) === undefined) {
54
+ let oFound = node.topics.find(a => a.id === msg.topic.toString());
55
+ if (oFound === undefined) {
54
56
  node.topics.push({ id: msg.topic.toString(), val: ret });
57
+ } else {
58
+ oFound.val = ret;
55
59
  }
56
60
 
57
61
  var quantita = 0;
@@ -77,12 +81,24 @@ module.exports = function (RED) {
77
81
  msg.average = moltiplicazione / quantita; // Average
78
82
  msg.measurements = quantita; // Topics
79
83
  } else if (node.math === "subtract") {
80
-
81
- let risultato = node.topics[0].val;
84
+ let risultato = 0;
85
+ if (node.subtractstartfrom !== "") {
86
+ try {
87
+ risultato = node.topics.find(m => m.id === node.subtractstartfrom).val;
88
+ } catch (error) {
89
+ setNodeStatus({ fill: "grey", shape: "ring", text: "Waiting for " + node.subtractstartfrom });
90
+ return;
91
+ }
92
+ } else {
93
+ setNodeStatus({ fill: "red", shape: "ring", text: "Please specify the topic form subtract to." });
94
+ return;
95
+ }
82
96
  quantita = 1;
83
- for (let index = 1; index < node.topics.length; index++) {
84
- risultato -= node.topics[index].val;
85
- ++quantita;
97
+ for (let index = 0; index < node.topics.length; index++) {
98
+ if (node.topics[index].id !== node.subtractstartfrom) {
99
+ risultato -= node.topics[index].val;
100
+ ++quantita;
101
+ }
86
102
  }
87
103
 
88
104
  msg.payload = risultato; // Sum
@@ -106,7 +122,7 @@ module.exports = function (RED) {
106
122
  } catch (error) {
107
123
  setNodeStatus({ fill: "red", shape: "ring", text: error.message });
108
124
  }
109
- setNodeStatus({ fill: "green", shape: "dot", text: "Sum " + msg.payload });
125
+ setNodeStatus({ fill: "green", shape: "dot", text: node.math + " " + msg.payload });
110
126
  node.send(msg);
111
127
  });
112
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-boolean-logic-ultimate",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
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": {