node-red-contrib-boolean-logic-ultimate 1.1.2 → 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,14 @@
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>
10
+ <p>
11
+ <b>Version 1.1.3</b> March 2024<br/>
12
+ - Comparator node: NEW: you can now reset both input values to *undefined*, by sending **msg.reset = true**.</br>
13
+ </p>
6
14
  <p>
7
15
  <b>Version 1.1.2</b> January 2024<br/>
8
16
  - NEW: added "normal" and "violated" as default accepted inputs, for compatibility with Home Assistant.</br>
package/README.md CHANGED
@@ -21,24 +21,9 @@ A set of Node-RED enhanced boolean logic and utility nodes, with persistent valu
21
21
  <br/>
22
22
  <br/>
23
23
 
24
- ### COMPATIBLES INPUT VALUES
25
- Other than true/false, all nodes accepts these strings and convert it to true/false. All nodes are compatible with Homeassistant output strings.
26
- |Input|Translated into|
27
- |--|--|
28
- | "on" | true |
29
- | "off" | false |
30
- | "active" | true |
31
- | "inactive" | false |
32
- | "open" | true |
33
- | "closed" or "close" | false |
34
- | "true" | true |
35
- | "false" | false |
36
- | "1" | true |
37
- | "0" | false |
38
- | "home" | true |
39
- | "not_home" | false |
40
-
41
- You can add your own translation command, thanks to the translator-config node.
24
+ ### HOME ASSISTANT COMPATIBLES INPUT VALUES
25
+ Other than true/false, all nodes accepts [Homeassistant](https://www.home-assistant.io) output strings.
26
+ You can **even add your own input translation word list**, thanks to the translator-config node.
42
27
 
43
28
  <br/>
44
29
  <br/>
@@ -66,10 +66,10 @@
66
66
  if (this.delayEvaluation === 0 || this.delayEvaluation === "0" || this.delayEvaluation === "" || this.delayEvaluation === undefined) {
67
67
  delayEvaluation = "";
68
68
  } else {
69
- delayEvaluation = "d(" + this.delayEvaluation + ")";
69
+ delayEvaluation = " (delay " + (this.delayEvaluation / 1000) + "s)";
70
70
  }
71
71
  if (typeof this.outputtriggeredby !== "undefined") trigger = this.outputtriggeredby === "all" ? "" : "t(" + this.triggertopic + ")";
72
- label = "Gate " + this.inputCount + filtered + delayEvaluation + trigger;
72
+ label = "Gate (" + this.inputCount + " input)" + filtered + delayEvaluation + trigger;
73
73
  if (this.name !== undefined && this.name.length > 0) {
74
74
  label += " (" + this.name + ")";
75
75
  }
@@ -17,7 +17,7 @@
17
17
  },
18
18
  topic2: {
19
19
  value: "", required: true
20
- }
20
+ }
21
21
  },
22
22
  inputs: 1,
23
23
  outputs: 1,
@@ -84,9 +84,13 @@
84
84
  | Comparator | It's the comparator. It compares the Topic 1 against the Topic 2. |
85
85
  | Topic 2 | It's the second topic to be evaluated against the first topic. |
86
86
 
87
- <br/>
88
87
 
89
- ### Outputs
88
+ ### Input
89
+
90
+ : reset (boolean) : `msg.reset = true` is used to reset both input values to ***undefined***. The node will execute only the *reset* command, regardless of other message properties.
91
+
92
+
93
+ ### Output
90
94
 
91
95
  1. Standard output
92
96
  : payload (boolean) : the standard output of the command.
@@ -6,7 +6,7 @@ module.exports = function (RED) {
6
6
  node.math = config.math === undefined ? "===" : config.math;
7
7
  node.topic1Value = undefined;
8
8
  node.topic2Value = undefined;
9
-
9
+
10
10
  function setNodeStatus({ fill, shape, text }) {
11
11
  let dDate = new Date();
12
12
  node.status({
@@ -41,6 +41,16 @@ module.exports = function (RED) {
41
41
  }
42
42
 
43
43
  node.on("input", function (msg) {
44
+ if (msg.hasOwnProperty("reset")) {
45
+ node.topic1Value = undefined;
46
+ node.topic2Value = undefined;
47
+ setNodeStatus({
48
+ fill: "grey",
49
+ shape: "ring",
50
+ text: "Reset",
51
+ });
52
+ return;
53
+ }
44
54
  if (!msg.hasOwnProperty("topic")) {
45
55
  setNodeStatus({
46
56
  fill: "red",
@@ -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
- oneditprepare: function () {
28
- if ($("#node-input-property").val() === "") $("#node-input-property").val("payload");
29
- $("#node-input-property").typedInput({ default: 'msg', types: ['msg'] });
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
- this.topics = {};
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[msg.topic.toString()] = ret;
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
- let somma = Object.keys(node.topics).reduce(function (a, b) {
60
+ node.topics.forEach((item) => {
61
+ somma += item.val;
59
62
  ++quantita;
60
- return a + node.topics[b];
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
- let moltiplicazione = Object.keys(node.topics).reduce(function (a, b) {
67
- try {
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
- }, 0);
75
+ });
75
76
  msg.payload = moltiplicazione; // Sum
76
- msg.average = undefined; // Average
77
+ msg.average = moltiplicazione / quantita; // Average
77
78
  msg.measurements = quantita; // Topics
78
79
  } else if (node.math === "subtract") {
79
- let values = []
80
- for (let row in node.topics) {
81
- if (node.topics.hasOwnProperty(row)) {
82
- ++quantita;
83
- values.push(node.topics[row]);
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.2",
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": {