node-red-contrib-boolean-logic-ultimate 1.1.3 → 1.1.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
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
# CHANGELOG
|
|
5
5
|
|
|
6
|
+
<p>
|
|
7
|
+
<b>Version 1.1.5</b> April 2024<br/>
|
|
8
|
+
- Math node: fixed an issue with the "subtract" operator. See contestual help in the node-red help tab.</br>
|
|
9
|
+
</p>
|
|
6
10
|
<p>
|
|
7
11
|
<b>Version 1.1.3</b> March 2024<br/>
|
|
8
12
|
- Comparator node: NEW: you can now reset both input values to *undefined*, by sending **msg.reset = true**.</br>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
math: {
|
|
13
13
|
value: "sum"
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
},
|
|
17
17
|
inputs: 1,
|
|
18
18
|
outputs: 1,
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
paletteLabel: function () {
|
|
25
25
|
return "MathUltimate";
|
|
26
26
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
oneditprepare: function () {
|
|
28
|
+
if ($("#node-input-property").val() === "") $("#node-input-property").val("payload");
|
|
29
|
+
$("#node-input-property").typedInput({ default: 'msg', types: ['msg'] });
|
|
30
|
+
}
|
|
31
31
|
});
|
|
32
32
|
</script>
|
|
33
33
|
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
|Property|Description|
|
|
63
63
|
|--|--|
|
|
64
64
|
| 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.
|
|
65
|
+
| Operation | Operation to be performed. For **subtract** operation, the **first topic** arriving to the node is the number to subtract to.|
|
|
66
66
|
|
|
67
67
|
<br/>
|
|
68
68
|
<br/>
|
|
@@ -4,7 +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
|
-
|
|
7
|
+
node.topics = [];
|
|
8
8
|
|
|
9
9
|
function setNodeStatus({ fill, shape, text }) {
|
|
10
10
|
let dDate = new Date();
|
|
@@ -31,7 +31,7 @@ module.exports = function (RED) {
|
|
|
31
31
|
|
|
32
32
|
// handle reset
|
|
33
33
|
if (msg.hasOwnProperty("reset")) {
|
|
34
|
-
node.topics =
|
|
34
|
+
node.topics = [];
|
|
35
35
|
setNodeStatus({ fill: "grey", shape: "ring", text: "Reset" });
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
@@ -50,52 +50,45 @@ module.exports = function (RED) {
|
|
|
50
50
|
|
|
51
51
|
// Sum
|
|
52
52
|
if (!isNaN(ret) && isFinite(ret)) {
|
|
53
|
-
node.topics
|
|
53
|
+
if (node.topics.find(a => a.id === msg.topic.toString()) === undefined) {
|
|
54
|
+
node.topics.push({ id: msg.topic.toString(), val: ret });
|
|
55
|
+
}
|
|
54
56
|
|
|
55
57
|
var quantita = 0;
|
|
56
|
-
|
|
58
|
+
let somma = 0;
|
|
57
59
|
if (node.math === "sum") {
|
|
58
|
-
|
|
60
|
+
node.topics.forEach((item) => {
|
|
61
|
+
somma += item.val;
|
|
59
62
|
++quantita;
|
|
60
|
-
|
|
61
|
-
}, 0);
|
|
63
|
+
});
|
|
62
64
|
msg.payload = somma; // Sum
|
|
63
65
|
msg.average = somma / quantita; // Average
|
|
64
66
|
msg.measurements = quantita; // Topics
|
|
65
67
|
} else if (node.math === "multiply") {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
let moltiplicazione = 1;
|
|
70
|
+
node.topics.forEach((item) => {
|
|
71
|
+
if (item.val !== 0) {
|
|
72
|
+
moltiplicazione *= item.val;
|
|
68
73
|
++quantita;
|
|
69
|
-
return (a > 0 ? a : 1) * node.topics[b]; // Avoid returning zero everytime
|
|
70
|
-
} catch (error) {
|
|
71
|
-
setNodeStatus({ fill: "red", shape: "ring", text: "Error " + error.message });
|
|
72
|
-
return 0;
|
|
73
74
|
}
|
|
74
|
-
}
|
|
75
|
+
});
|
|
75
76
|
msg.payload = moltiplicazione; // Sum
|
|
76
|
-
msg.average =
|
|
77
|
+
msg.average = moltiplicazione / quantita; // Average
|
|
77
78
|
msg.measurements = quantita; // Topics
|
|
78
79
|
} else if (node.math === "subtract") {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
function orderReverseNumbers(a, b) {
|
|
87
|
-
return b - a;
|
|
88
|
-
}
|
|
89
|
-
values.sort(orderReverseNumbers)
|
|
90
|
-
let risultato = values[0]
|
|
91
|
-
for (let index = 1; index < values.length; index++) {
|
|
92
|
-
risultato -= values[index];
|
|
80
|
+
|
|
81
|
+
let risultato = node.topics[0].val;
|
|
82
|
+
quantita = 1;
|
|
83
|
+
for (let index = 1; index < node.topics.length; index++) {
|
|
84
|
+
risultato -= node.topics[index].val;
|
|
85
|
+
++quantita;
|
|
93
86
|
}
|
|
87
|
+
|
|
94
88
|
msg.payload = risultato; // Sum
|
|
95
89
|
msg.average = risultato / quantita; // Average
|
|
96
90
|
msg.measurements = quantita; // Topics
|
|
97
91
|
}
|
|
98
|
-
|
|
99
92
|
// overwrite topic if configured
|
|
100
93
|
if (config.name) {
|
|
101
94
|
msg.topic = config.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-boolean-logic-ultimate",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.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": {
|