node-red-contrib-boolean-logic-ultimate
Advanced tools
Comparing version 1.0.30 to 1.0.31
@@ -1,48 +0,54 @@ | ||
module.exports = function(RED) { | ||
function FilterUltimate(config) { | ||
RED.nodes.createNode(this,config); | ||
module.exports = function (RED) { | ||
function FilterUltimate(config) { | ||
RED.nodes.createNode(this, config); | ||
this.config = config; | ||
var node = this; | ||
function setNodeStatus({fill, shape, text}) | ||
{ | ||
function setNodeStatus({ fill, shape, text }) { | ||
var dDate = new Date(); | ||
node.status({fill: fill,shape: shape,text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")"}) | ||
node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" }) | ||
} | ||
setNodeStatus( {fill: "grey" ,shape: "dot" ,text: "Waiting"}); | ||
setNodeStatus({ fill: "grey", shape: "dot", text: "Waiting" }); | ||
this.on('input', function (msg) { | ||
var sTopic = node.config.name; | ||
if (msg.hasOwnProperty("topic")){ | ||
if (msg.hasOwnProperty("topic")) { | ||
sTopic = (msg.topic === "" ? sTopic : msg.topic); | ||
} | ||
if (typeof msg.payload !== "undefined") { | ||
var bRes = ToBoolean(msg.payload); | ||
if (typeof bRes === "undefined") return; | ||
// 24/01/2020 Clone input message and replace only relevant topics | ||
var msgTrue = RED.util.cloneMessage(msg); | ||
msgTrue.topic = sTopic; | ||
msgTrue.payload = true; | ||
var msgFalse = RED.util.cloneMessage(msg); | ||
msgFalse.topic = sTopic; | ||
msgFalse.payload = false; | ||
if (bRes === true) { | ||
setNodeStatus({ fill: "green", shape: "dot", text: "(Send) true" }); | ||
node.send([msgTrue, null]); | ||
} else | ||
{ | ||
setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) false"}); | ||
node.send([null, msgFalse]); | ||
} | ||
if (!msg.hasOwnProperty("payload")) { | ||
setNodeStatus({ fill: "red", shape: "dot", text: "No payload property from " + sTopic }); | ||
return; | ||
} | ||
}); | ||
function ToBoolean( value ) { | ||
if (msg.payload !== true && msg.payload !== false) { | ||
setNodeStatus({ fill: "red", shape: "dot", text: "Received non boolean value from " + sTopic }); | ||
return; | ||
} | ||
var bRes = ToBoolean(msg.payload); | ||
if (typeof bRes === "undefined") return; | ||
// 24/01/2020 Clone input message and replace only relevant topics | ||
var msgTrue = RED.util.cloneMessage(msg); | ||
msgTrue.topic = sTopic; | ||
msgTrue.payload = true; | ||
var msgFalse = RED.util.cloneMessage(msg); | ||
msgFalse.topic = sTopic; | ||
msgFalse.payload = false; | ||
if (bRes === true) { | ||
setNodeStatus({ fill: "green", shape: "dot", text: "(Send) true" }); | ||
node.send([msgTrue, null]); | ||
} else { | ||
setNodeStatus({ fill: "green", shape: "dot", text: "(Send) false" }); | ||
node.send([null, msgFalse]); | ||
} | ||
return; | ||
}); | ||
function ToBoolean(value) { | ||
var res = false; | ||
@@ -53,7 +59,7 @@ var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/ | ||
res = value; | ||
} | ||
else if( typeof value === 'number' || typeof value === 'string' ) { | ||
} | ||
else if (typeof value === 'number' || typeof value === 'string') { | ||
// Is it formated as a decimal number? | ||
if( decimal.test( value ) ) { | ||
var v = parseFloat( value ); | ||
if (decimal.test(value)) { | ||
var v = parseFloat(value); | ||
res = v != 0; | ||
@@ -65,9 +71,9 @@ } | ||
} | ||
return res; | ||
}; | ||
} | ||
} | ||
RED.nodes.registerType("FilterUltimate",FilterUltimate); | ||
RED.nodes.registerType("FilterUltimate", FilterUltimate); | ||
} |
@@ -29,2 +29,6 @@ module.exports = function (RED) { | ||
if (sIncomingTopic == node.sTriggerTopic) { | ||
if (msg.payload !== true && msg.payload !== false) { | ||
setNodeStatus({ fill: "red", shape: "dot", text: "Received non boolean value from " + sIncomingTopic }); | ||
return; | ||
} | ||
if (msg.hasOwnProperty("play")) { | ||
@@ -43,7 +47,7 @@ node.currentMsg.isReplay = true; | ||
return; | ||
} else if (ToBoolean(msg.payload) === true) { | ||
} else if (msg.payload === true) { | ||
node.bInviaMessaggio = true; | ||
setNodeStatus({ fill: "green", shape: "dot", text: "-> pass" }); | ||
return; | ||
} else if (ToBoolean(msg.payload) === false) { | ||
} else if (msg.payload === false) { | ||
node.bInviaMessaggio = false; | ||
@@ -50,0 +54,0 @@ setNodeStatus({ fill: "red", shape: "dot", text: "|| stop (stored last msg)" }); |
@@ -5,3 +5,3 @@ # node-red-contrib-boolean-logic-ultimate | ||
<p> | ||
<b>Version 1.0.30</b> August 2021<br/> | ||
<b>Version 1.0.31</b> August 2021<br/> | ||
- NEW: Boolean-Logic-Ulimate can now strict filter for input payload, by accepting only boolean true/false values. If the option is not enabled, the node will continue to try to transform the input payload to a suitable boolean value.</br> | ||
@@ -8,0 +8,0 @@ </p> |
{ | ||
"name": "node-red-contrib-boolean-logic-ultimate", | ||
"version": "1.0.30", | ||
"version": "1.0.31", | ||
"description": "A set of Node-RED enhanced boolean logic node, flow interruption node, blinker node, invert node, filter node, with persisten values after reboot and more.", | ||
@@ -5,0 +5,0 @@ "author": "Supergiovane (https://github.com/Supergiovane)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
627131
624