node-red-contrib-boolean-logic-ultimate 1.1.23 → 1.1.25
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 +16 -1
- package/README.md +12 -1
- package/boolean-logic-ultimate/translator-config.html +1 -1
- package/boolean-logic-ultimate/utils.js +25 -14
- package/image.png +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,22 @@
|
|
|
4
4
|
# CHANGELOG
|
|
5
5
|
|
|
6
6
|
<p>
|
|
7
|
-
<b>Version 1.1.
|
|
7
|
+
<b>Version 1.1.25</b> January 2025<br/>
|
|
8
|
+
- BREAKING CHANGE
|
|
9
|
+
- BREAKING CHANGE
|
|
10
|
+
- BREAKING CHANGE
|
|
11
|
+
- Numerical values are now evaluated as string values and translated like any other word in translation table. That means, 1 and numbers major than 1 are not equal to true anymore, and 0 is not equal to false anymore. If you inputs numerical values as boolean (bad attitude), please fix your flows by change it to boolean.</br>
|
|
12
|
+
- BREAKING CHANGE
|
|
13
|
+
- BREAKING CHANGE
|
|
14
|
+
- BREAKING CHANGE
|
|
15
|
+
|
|
16
|
+
</p>
|
|
17
|
+
<p>
|
|
18
|
+
<b>Version 1.1.24</b> January 2025<br/>
|
|
19
|
+
- Translator node. added js evaluation of the values. For example "{{value>=50}}:true".</br>
|
|
20
|
+
</p>
|
|
21
|
+
<p>
|
|
22
|
+
<b>Version 1.1.23</b> December 2024<br/>
|
|
8
23
|
- Math node. fixed multiply by zero issue.</br>
|
|
9
24
|
</p>
|
|
10
25
|
<p>
|
package/README.md
CHANGED
|
@@ -20,11 +20,22 @@ A set of Node-RED enhanced boolean logic and utility nodes, with persistent valu
|
|
|
20
20
|
<br/>
|
|
21
21
|
<br/>
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
# TRANSLATOR NODE
|
|
24
24
|
|
|
25
25
|
Other than true/false, all nodes accepts [Homeassistant](https://www.home-assistant.io) output strings.
|
|
26
26
|
|
|
27
27
|
You can **even add your own input translation word list**, thanks to the translator-config node.
|
|
28
|
+
The translator node can translate an input payload, to a true/false boolean values.<br />
|
|
29
|
+
Each row in the text box, represents a translation command. <br/>
|
|
30
|
+
There are some default translation's rows, to make the *boolean-logic-ultimate* nodes compatible with Homeassistant as default. <br/>
|
|
31
|
+
You can add your own translation row.<br/>
|
|
32
|
+
|
|
33
|
+
| | Description |
|
|
34
|
+
| --------- | ---------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| Translate | Add, delete or edit your own translation command. The row's translation command must be **input string:true(or false)**. For example: <code>open:true</code> <code>closed:false</code>. You can also use an expressions to be evaluated, like this <code>{{value>=50}}:true</code> and <code>{{value<50}}:false</code>. In this case, the tranlsator will evaluate (javascript eval) the expression and, if true, returns the choosen value. |
|
|
36
|
+
|
|
37
|
+

|
|
38
|
+
|
|
28
39
|
|
|
29
40
|
<br/>
|
|
30
41
|
<br/>
|
|
@@ -54,7 +54,7 @@ You can add your own translation row.<br/>
|
|
|
54
54
|
|
|
55
55
|
|Property|Description|
|
|
56
56
|
|--|--|
|
|
57
|
-
| Translate | Add, delete or edit your own translation command. The row's translation command must be **input string:true(or false)**. For example: <code>open:true</code> <code>closed:false</code> |
|
|
57
|
+
| Translate | Add, delete or edit your own translation command. The row's translation command must be **input string:true(or false)**. For example: <code>open:true</code> <code>closed:false</code>. You can also use an expressions to be evaluated, like this <code>{{value>=50}}:true</code> and <code>{{value<50}}:false</code>. In this case, the tranlsator will evaluate (javascript eval) the expression and, if true, returns the choosen value. |
|
|
58
58
|
|
|
59
59
|
<br/>
|
|
60
60
|
|
|
@@ -4,20 +4,30 @@ module.exports.ToBoolean = function ToBoolean(value, _configTranslationNode) {
|
|
|
4
4
|
|
|
5
5
|
if (typeof value === "boolean") {
|
|
6
6
|
return value;
|
|
7
|
-
} else if (typeof value === "string") {
|
|
7
|
+
} else if (typeof value === "string" || typeof value === "number") {
|
|
8
|
+
if (typeof value === "number") value = value.toString(); // We work with strings
|
|
8
9
|
try {
|
|
9
10
|
let translationTable = [];
|
|
11
|
+
value = value.toLowerCase();
|
|
10
12
|
if (_configTranslationNode === null) {
|
|
11
13
|
translationTable = DEFAULTTRANSLATIONINPUT.split("\n");
|
|
12
14
|
} else {
|
|
13
15
|
translationTable = _configTranslationNode.commandText.split("\n");
|
|
14
16
|
}
|
|
15
17
|
for (let index = 0; index < translationTable.length; index++) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
value
|
|
20
|
-
inputPayloadToBeTranslated.
|
|
18
|
+
// HA Style evaluation in the format "{{value>=0}}"
|
|
19
|
+
let inputPayloadToBeTranslated = translationTable[index].toLowerCase().split(":")[0];
|
|
20
|
+
if (inputPayloadToBeTranslated.indexOf("{{") > -1 && inputPayloadToBeTranslated.indexOf("}}") > -1) {
|
|
21
|
+
// Eval content of the brackets {{value<=0}}, HA style
|
|
22
|
+
inputPayloadToBeTranslated = inputPayloadToBeTranslated.replace("{{", "").replace("}}", "").replace("value", value); // Set the word value to real value
|
|
23
|
+
if (eval(inputPayloadToBeTranslated)) {
|
|
24
|
+
return translationTable[index].split(":")[1] === "true"
|
|
25
|
+
? true
|
|
26
|
+
: false;
|
|
27
|
+
} // Eval the operation
|
|
28
|
+
} else if (
|
|
29
|
+
// Normal string value
|
|
30
|
+
value === inputPayloadToBeTranslated
|
|
21
31
|
) {
|
|
22
32
|
return translationTable[index].split(":")[1] === "true"
|
|
23
33
|
? true
|
|
@@ -27,15 +37,16 @@ module.exports.ToBoolean = function ToBoolean(value, _configTranslationNode) {
|
|
|
27
37
|
} catch (error) {
|
|
28
38
|
console.log("Boolean-Logic-Ultimate:utils:toBoolean: " + error.message);
|
|
29
39
|
}
|
|
30
|
-
} else if (typeof value === "number") {
|
|
31
|
-
// Is it formated as a decimal number?
|
|
32
|
-
if (decimal.test(value)) {
|
|
33
|
-
res = parseFloat(value) != 0;
|
|
34
|
-
} else {
|
|
35
|
-
res = value.toLowerCase() === "true";
|
|
36
|
-
}
|
|
37
|
-
return res;
|
|
38
40
|
}
|
|
41
|
+
// else if (typeof value === "number") {
|
|
42
|
+
// // Is it formated as a decimal number?
|
|
43
|
+
// if (decimal.test(value)) {
|
|
44
|
+
// res = parseFloat(value) != 0;
|
|
45
|
+
// } else {
|
|
46
|
+
// res = value.toLowerCase() === "true";
|
|
47
|
+
// }
|
|
48
|
+
// return res;
|
|
49
|
+
// }
|
|
39
50
|
};
|
|
40
51
|
|
|
41
52
|
module.exports.ToAny = function ToAny(value, _configTranslationNode) {
|
package/image.png
ADDED
|
Binary file
|
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.25",
|
|
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": {
|