node-red-contrib-boolean-logic-ultimate 1.0.62 → 1.1.0
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 +8 -0
- package/README.md +11 -10
- package/boolean-logic-ultimate/BlinkerUltimate.html +1 -1
- package/boolean-logic-ultimate/BooleanLogicUltimate.html +13 -2
- package/boolean-logic-ultimate/BooleanLogicUltimate.js +488 -338
- package/boolean-logic-ultimate/Comparator.html +102 -0
- package/boolean-logic-ultimate/Comparator.js +99 -0
- package/boolean-logic-ultimate/FilterUltimate.html +16 -4
- package/boolean-logic-ultimate/FilterUltimate.js +67 -46
- package/boolean-logic-ultimate/ImpulseUltimate.html +1 -1
- package/boolean-logic-ultimate/InterruptFlowUltimate.html +15 -3
- package/boolean-logic-ultimate/InterruptFlowUltimate.js +155 -93
- package/boolean-logic-ultimate/InvertUltimate.html +14 -5
- package/boolean-logic-ultimate/InvertUltimate.js +74 -46
- package/boolean-logic-ultimate/RailwaySwitchUltimate.html +13 -2
- package/boolean-logic-ultimate/RailwaySwitchUltimate.js +110 -71
- package/boolean-logic-ultimate/SimpleOutputUltimate.html +1 -1
- package/boolean-logic-ultimate/SumUltimate.html +1 -1
- package/boolean-logic-ultimate/toggleUltimate.html +13 -3
- package/boolean-logic-ultimate/toggleUltimate.js +1 -1
- package/boolean-logic-ultimate/translator-config.html +63 -0
- package/boolean-logic-ultimate/translator-config.js +8 -0
- package/boolean-logic-ultimate/utils.js +52 -43
- package/package.json +4 -2
|
@@ -53,7 +53,7 @@ This is useful if you need to simply send a true or false payload.
|
|
|
53
53
|
|
|
54
54
|
|Property|Description|
|
|
55
55
|
|--|--|
|
|
56
|
-
| Input |
|
|
56
|
+
| 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"* |
|
|
57
57
|
|
|
58
58
|
<br/>
|
|
59
59
|
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
|
|
62
62
|
|Property|Description|
|
|
63
63
|
|--|--|
|
|
64
|
-
| Input |
|
|
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
65
|
| Operation | Operation to be performed. |
|
|
66
66
|
|
|
67
67
|
<br/>
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
value: "Toggle"
|
|
8
8
|
},
|
|
9
9
|
valueToToggle: { value: "true" },
|
|
10
|
-
payloadPropName: { value: "payload", required: false }
|
|
10
|
+
payloadPropName: { value: "payload", required: false },
|
|
11
|
+
translatorConfig: { type: "translator-config", required: false }
|
|
11
12
|
},
|
|
12
13
|
inputs: 1,
|
|
13
14
|
outputs: 1,
|
|
@@ -55,7 +56,15 @@
|
|
|
55
56
|
<i class="fa fa-home"></i> Output Home Assistant "on"/"off" instead of true/false
|
|
56
57
|
</label>
|
|
57
58
|
</div> -->
|
|
58
|
-
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<br />
|
|
61
|
+
<b>Translator</b>
|
|
62
|
+
<br />
|
|
63
|
+
<label for="node-input-translatorConfig">
|
|
64
|
+
<font color="green" size="4px"><i class="fa fa-sign-in" aria-hidden="true"></i></font> Input
|
|
65
|
+
</label>
|
|
66
|
+
<input type="text" id="node-input-translatorConfig" />
|
|
67
|
+
</div>
|
|
59
68
|
|
|
60
69
|
</script>
|
|
61
70
|
|
|
@@ -64,7 +73,8 @@
|
|
|
64
73
|
|
|
65
74
|
|Property|Description|
|
|
66
75
|
|--|--|
|
|
67
|
-
| Input |
|
|
76
|
+
| 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"* |
|
|
77
|
+
| Translator Input | Translates the incoming <code>payload</code> value, to true/false. This allows the compatibility with, for example, **HomeAssistant** nodes. |
|
|
68
78
|
|
|
69
79
|
* Input message
|
|
70
80
|
|
|
@@ -4,7 +4,7 @@ module.exports = function (RED) {
|
|
|
4
4
|
this.config = config;
|
|
5
5
|
var node = this;
|
|
6
6
|
const utils = require("./utils.js");
|
|
7
|
-
node.valueToToggle = config.valueToToggle === undefined ? true : utils.ToBoolean(config.valueToToggle);
|
|
7
|
+
node.valueToToggle = config.valueToToggle === undefined ? true : utils.ToBoolean(config.valueToToggle, RED.nodes.getNode(config.translatorConfig)) // Retrieve the config node. It can be null, but it's handled in utils.js);
|
|
8
8
|
|
|
9
9
|
function setNodeStatus({ fill, shape, text }) {
|
|
10
10
|
let dDate = new Date();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('translator-config', {
|
|
3
|
+
category: 'config',
|
|
4
|
+
defaults: {
|
|
5
|
+
name: { value: "" },
|
|
6
|
+
commandText: { value: 'on:true\noff:false\nactive:true\ninactive:false\nopen:true\nclosed:false\nclose:false\n1:true\n0:false\ntrue:true\nfalse:false\nhome:true\nnot_home:false', required: false }
|
|
7
|
+
},
|
|
8
|
+
label: function () {
|
|
9
|
+
return this.name;
|
|
10
|
+
},
|
|
11
|
+
oneditprepare: function () {
|
|
12
|
+
var node = this;
|
|
13
|
+
node.editor = RED.editor.createEditor({
|
|
14
|
+
id: 'node-input-editorcommandText',
|
|
15
|
+
mode: 'ace/mode/text',
|
|
16
|
+
value: node.commandText
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
oneditsave: function () {
|
|
20
|
+
var node = this;
|
|
21
|
+
node.commandText = node.editor.getValue();
|
|
22
|
+
node.editor.destroy();
|
|
23
|
+
delete node.editor;
|
|
24
|
+
},
|
|
25
|
+
oneditcancel: function () {
|
|
26
|
+
var node = this;
|
|
27
|
+
node.editor.destroy();
|
|
28
|
+
delete node.editor;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script type="text/html" data-template-name="translator-config">
|
|
34
|
+
<div class="form-row">
|
|
35
|
+
<label for="node-config-input-name">
|
|
36
|
+
<i class="fa fa-tag"></i> Name
|
|
37
|
+
</label>
|
|
38
|
+
<input type="text" id="node-config-input-name">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label style="width:300px;" for="node-input-commandText"><i class="fa fa-tasks"></i> Translate</label>
|
|
42
|
+
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-editorcommandText"></div>
|
|
43
|
+
</div>
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<script type="text/markdown" data-help-name="translator-config">
|
|
47
|
+
<p>This node translates the input msg to valid true/false values.<p>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
It can translate an input payload, to a true/false boolean values.<br />
|
|
51
|
+
Each row in the text box, represents a translation command. <br/>
|
|
52
|
+
There are some default translation's rows, to make the *boolean-logic-ultimate* nodes compatible with Homeassistant. <br/>
|
|
53
|
+
You can add your own translation row.<br/>
|
|
54
|
+
|
|
55
|
+
|Property|Description|
|
|
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> |
|
|
58
|
+
|
|
59
|
+
<br/>
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[Find it useful?](https://www.paypal.me/techtoday)
|
|
63
|
+
</script>
|
|
@@ -1,48 +1,57 @@
|
|
|
1
|
-
module.exports.ToBoolean = function ToBoolean(value) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (value.toLowerCase() === "home") return true;
|
|
26
|
-
if (value.toLowerCase() === "not_home") return false;
|
|
27
|
-
|
|
28
|
-
} else if (typeof value === 'number') {
|
|
29
|
-
// Is it formated as a decimal number?
|
|
30
|
-
if (decimal.test(value)) {
|
|
31
|
-
res = parseFloat(value) != 0;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
res = value.toLowerCase() === "true";
|
|
1
|
+
module.exports.ToBoolean = function ToBoolean(value, _configTranslationNode) {
|
|
2
|
+
let res = false;
|
|
3
|
+
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/;
|
|
4
|
+
|
|
5
|
+
if (typeof value === "boolean") {
|
|
6
|
+
return value;
|
|
7
|
+
} else if (typeof value === "string") {
|
|
8
|
+
try {
|
|
9
|
+
let translationTable = [];
|
|
10
|
+
if (_configTranslationNode === null) {
|
|
11
|
+
translationTable = DEFAULTTRANSLATIONINPUT.split("\n");
|
|
12
|
+
} else {
|
|
13
|
+
translationTable = _configTranslationNode.commandText.split("\n");
|
|
14
|
+
}
|
|
15
|
+
for (let index = 0; index < translationTable.length; index++) {
|
|
16
|
+
let inputPayloadToBeTranslated = translationTable[index].split(":")[0];
|
|
17
|
+
let outputBoolean = Boolean(translationTable[index].split(":")[1]);
|
|
18
|
+
if (
|
|
19
|
+
value.toLowerCase() === inputPayloadToBeTranslated.toLowerCase() &&
|
|
20
|
+
inputPayloadToBeTranslated.toLowerCase() !== ""
|
|
21
|
+
) {
|
|
22
|
+
return translationTable[index].split(":")[1] === "true"
|
|
23
|
+
? true
|
|
24
|
+
: false;
|
|
35
25
|
}
|
|
36
|
-
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.log("Boolean-Logic-Ultimate:utils:toBoolean: " + error.message);
|
|
37
29
|
}
|
|
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
|
+
}
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
module.exports.fetchFromObject = function fetchFromObject(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
41
|
+
module.exports.fetchFromObject = function fetchFromObject(
|
|
42
|
+
_msg,
|
|
43
|
+
_payloadPropName
|
|
44
|
+
) {
|
|
45
|
+
// The output cannot be an oblect. In case, return undefined.
|
|
46
|
+
var _index = _payloadPropName.indexOf(".");
|
|
47
|
+
if (_index > -1) {
|
|
48
|
+
return fetchFromObject(
|
|
49
|
+
_msg[_payloadPropName.substring(0, _index)],
|
|
50
|
+
_payloadPropName.substr(_index + 1)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (typeof _msg[_payloadPropName] === "object") return undefined;
|
|
54
|
+
return _msg[_payloadPropName];
|
|
48
55
|
};
|
|
56
|
+
const DEFAULTTRANSLATIONINPUT =
|
|
57
|
+
"on:true\noff:false\nactive:true\ninactive:false\nopen:true\nclosed:false\nclose:false\n1:true\n0:false\ntrue:true\nfalse:false\nhome:true\nnot_home:false";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-boolean-logic-ultimate",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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": {
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
"ImpulseUltimate": "boolean-logic-ultimate/ImpulseUltimate.js",
|
|
33
33
|
"SumUltimate": "boolean-logic-ultimate/SumUltimate.js",
|
|
34
34
|
"toggleUltimate": "boolean-logic-ultimate/toggleUltimate.js",
|
|
35
|
-
"RailwaySwitchUltimate": "boolean-logic-ultimate/RailwaySwitchUltimate.js"
|
|
35
|
+
"RailwaySwitchUltimate": "boolean-logic-ultimate/RailwaySwitchUltimate.js",
|
|
36
|
+
"Comparator": "boolean-logic-ultimate/Comparator.js",
|
|
37
|
+
"translator-config": "boolean-logic-ultimate/translator-config.js"
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
}
|