node-red-contrib-boolean-logic-ultimate 1.1.3 → 1.1.6
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,14 @@
|
|
|
3
3
|
|
|
4
4
|
# CHANGELOG
|
|
5
5
|
|
|
6
|
+
<p>
|
|
7
|
+
<b>Version 1.1.6</b> April 2024<br/>
|
|
8
|
+
- Math node: in SUBTRACT mode, now you must set a msg.topic to start subtracting from.</br>
|
|
9
|
+
</p>
|
|
10
|
+
<p>
|
|
11
|
+
<b>Version 1.1.5</b> April 2024<br/>
|
|
12
|
+
- Math node: fixed an issue with the "subtract" operator. See contestual help in the node-red help tab.</br>
|
|
13
|
+
</p>
|
|
6
14
|
<p>
|
|
7
15
|
<b>Version 1.1.3</b> March 2024<br/>
|
|
8
16
|
- Comparator node: NEW: you can now reset both input values to *undefined*, by sending **msg.reset = true**.</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,
|
|
@@ -24,10 +24,17 @@
|
|
|
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
|
+
$("#node-input-math").on('change', function () {
|
|
31
|
+
if ($("#node-input-math").val() === "subtract") {
|
|
32
|
+
$("#divSubtractFirst").show()
|
|
33
|
+
} else {
|
|
34
|
+
$("#divSubtractFirst").hide()
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
}
|
|
31
38
|
});
|
|
32
39
|
</script>
|
|
33
40
|
|
|
@@ -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
|
|
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
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,7 +4,8 @@ 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.subtractstartfrom = config.subtractstartfrom === undefined ? "" : config.subtractstartfrom;
|
|
8
|
+
node.topics = [];
|
|
8
9
|
|
|
9
10
|
function setNodeStatus({ fill, shape, text }) {
|
|
10
11
|
let dDate = new Date();
|
|
@@ -31,7 +32,7 @@ module.exports = function (RED) {
|
|
|
31
32
|
|
|
32
33
|
// handle reset
|
|
33
34
|
if (msg.hasOwnProperty("reset")) {
|
|
34
|
-
node.topics =
|
|
35
|
+
node.topics = [];
|
|
35
36
|
setNodeStatus({ fill: "grey", shape: "ring", text: "Reset" });
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
@@ -50,52 +51,60 @@ module.exports = function (RED) {
|
|
|
50
51
|
|
|
51
52
|
// Sum
|
|
52
53
|
if (!isNaN(ret) && isFinite(ret)) {
|
|
53
|
-
node.topics
|
|
54
|
+
let oFound = node.topics.find(a => a.id === msg.topic.toString());
|
|
55
|
+
if (oFound === undefined) {
|
|
56
|
+
node.topics.push({ id: msg.topic.toString(), val: ret });
|
|
57
|
+
} else {
|
|
58
|
+
oFound.val = ret;
|
|
59
|
+
}
|
|
54
60
|
|
|
55
61
|
var quantita = 0;
|
|
56
|
-
|
|
62
|
+
let somma = 0;
|
|
57
63
|
if (node.math === "sum") {
|
|
58
|
-
|
|
64
|
+
node.topics.forEach((item) => {
|
|
65
|
+
somma += item.val;
|
|
59
66
|
++quantita;
|
|
60
|
-
|
|
61
|
-
}, 0);
|
|
67
|
+
});
|
|
62
68
|
msg.payload = somma; // Sum
|
|
63
69
|
msg.average = somma / quantita; // Average
|
|
64
70
|
msg.measurements = quantita; // Topics
|
|
65
71
|
} else if (node.math === "multiply") {
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
|
|
73
|
+
let moltiplicazione = 1;
|
|
74
|
+
node.topics.forEach((item) => {
|
|
75
|
+
if (item.val !== 0) {
|
|
76
|
+
moltiplicazione *= item.val;
|
|
68
77
|
++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
78
|
}
|
|
74
|
-
}
|
|
79
|
+
});
|
|
75
80
|
msg.payload = moltiplicazione; // Sum
|
|
76
|
-
msg.average =
|
|
81
|
+
msg.average = moltiplicazione / quantita; // Average
|
|
77
82
|
msg.measurements = quantita; // Topics
|
|
78
83
|
} else if (node.math === "subtract") {
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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;
|
|
84
91
|
}
|
|
92
|
+
} else {
|
|
93
|
+
setNodeStatus({ fill: "red", shape: "ring", text: "Please specify the topic form subtract to." });
|
|
94
|
+
return;
|
|
85
95
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
risultato -= values[index];
|
|
96
|
+
quantita = 1;
|
|
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
|
+
}
|
|
93
102
|
}
|
|
103
|
+
|
|
94
104
|
msg.payload = risultato; // Sum
|
|
95
105
|
msg.average = risultato / quantita; // Average
|
|
96
106
|
msg.measurements = quantita; // Topics
|
|
97
107
|
}
|
|
98
|
-
|
|
99
108
|
// overwrite topic if configured
|
|
100
109
|
if (config.name) {
|
|
101
110
|
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.6",
|
|
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": {
|