node-red-contrib-boolean-logic-ultimate
Advanced tools
Comparing version
@@ -14,3 +14,9 @@ module.exports = function(RED) { | ||
//node.send({ req: req }); | ||
DeletePersistFile(req.query.nodeid); | ||
// Detele the persist file | ||
//var _node = RED.nodes.getNode(req.query.nodeid); // Gets node object from nodeit, because when called from the config html, the node object is not defined | ||
var _nodeid = req.query.nodeid; | ||
try { | ||
if (fs.existsSync("states/" + _nodeid.toString())) fs.unlinkSync("states/" + _nodeid.toString()); | ||
} catch (error) { | ||
} | ||
res.json({ status: 220 }); | ||
@@ -25,14 +31,14 @@ }); | ||
node.jSonStates = JSON.parse(contents); | ||
node.status({fill: "blue",shape: "ring",text: "Loaded persistent states (" + Object.keys(node.jSonStates).length + " total)."}); | ||
setNodeStatus({fill: "blue",shape: "ring",text: "Loaded persistent states (" + Object.keys(node.jSonStates).length + " total)."}); | ||
} | ||
} catch (error) { | ||
node.status({fill: "grey",shape: "ring",text: "No persistent states"}); | ||
setNodeStatus({fill: "grey",shape: "ring",text: "No persistent states"}); | ||
} | ||
} else { | ||
node.status({fill: "yellow",shape: "dot",text: "Waiting for input states"}); | ||
setNodeStatus({fill: "yellow",shape: "dot",text: "Waiting for input states"}); | ||
} | ||
// 14/08/2019 If the inputs are to be initialized, create a dummy items in the array | ||
// 14/08/2019 If some inputs are to be initialized, create a dummy items in the array | ||
initUndefinedInputs(); | ||
@@ -77,3 +83,3 @@ | ||
} catch (error) { | ||
node.status({fill: "red",shape: "dot",text: "Node cannot write to filesystem: " + error}); | ||
setNodeStatus({fill: "red",shape: "dot",text: "Node cannot write to filesystem: " + error}); | ||
} | ||
@@ -107,3 +113,3 @@ } | ||
{ | ||
node.status({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value}); | ||
setNodeStatus({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value}); | ||
} | ||
@@ -116,12 +122,6 @@ } else | ||
else if(keyCount > node.config.inputCount ) { | ||
node.warn( | ||
(node.config.name !== undefined && node.config.name.length > 0 | ||
? node.config.name : "BooleanLogicUltimate") | ||
+ " [Logic]: More than the specified " | ||
+ node.config.inputCount + " topics received, resetting. Will not output new value until " + node.config.inputCount + " new topics have been received."); | ||
node.jSonStates = {}; | ||
DeletePersistFile(node.id); | ||
DisplayUnkownStatus(); | ||
setNodeStatus({ fill: "gray", shape: "ring", text: "Reset due to unexpected new topic"}); | ||
DeletePersistFile(); | ||
} else { | ||
node.status({ fill: "green", shape: "ring", text: " Arrived topic " + keyCount + " of " + node.config.inputCount}); | ||
setNodeStatus({ fill: "green", shape: "ring", text: "Arrived topic " + keyCount + " of " + node.config.inputCount}); | ||
} | ||
@@ -135,3 +135,3 @@ } | ||
// Delete persistent states on change/deploy | ||
DeletePersistFile(node.id); | ||
DeletePersistFile(); | ||
} else { | ||
@@ -143,10 +143,9 @@ // This node is being restarted | ||
function DeletePersistFile (_nodeid){ | ||
function DeletePersistFile (){ | ||
// Detele the persist file | ||
var _node = RED.nodes.getNode(_nodeid); // Gets node object from nodeit, because when called from the config html, the node object is not defined | ||
try { | ||
if (fs.existsSync("states/" + _nodeid.toString())) fs.unlinkSync("states/" + _nodeid.toString()); | ||
_node.status({fill: "red",shape: "ring",text: "Persistent states deleted ("+_nodeid.toString()+")."}); | ||
if (fs.existsSync("states/" + node.id.toString())) fs.unlinkSync("states/" + node.id.toString()); | ||
setNodeStatus({fill: "red",shape: "ring",text: "Persistent states deleted ("+node.id.toString()+")."}); | ||
} catch (error) { | ||
_node.status({fill: "red",shape: "ring",text: "Error deleting persistent file: " + error.toString()}); | ||
setNodeStatus({fill: "red",shape: "ring",text: "Error deleting persistent file: " + error.toString()}); | ||
} | ||
@@ -162,8 +161,8 @@ node.jSonStates = {}; // Resets inputs | ||
var nTotalDummyToCreate = Number(node.config.inputCount) - Object.keys(node.jSonStates).length; | ||
RED.log.info("BooleanLogicUltimate: Will create " + nTotalDummyToCreate + " dummy (" + node.sInitializeWith + ") values") | ||
for (let index = 0; index < nTotalDummyToCreate; index++) { | ||
node.jSonStates["dummy" + index] = node.sInitializeWith === "false" ? false : true; | ||
} | ||
if (nTotalDummyToCreate > 0) { | ||
setTimeout(() => { node.status({fill: "green",shape: "ring",text: "Initialized " + nTotalDummyToCreate + " undefined inputs with " + node.sInitializeWith});}, 4000) | ||
RED.log.info("BooleanLogicUltimate: Will create " + nTotalDummyToCreate + " dummy (" + node.sInitializeWith + ") values") | ||
for (let index = 0; index < nTotalDummyToCreate; index++) { | ||
node.jSonStates["dummy" + index] = node.sInitializeWith === "false" ? false : true; | ||
} | ||
setTimeout(() => { setNodeStatus({fill: "green",shape: "ring",text: "Initialized " + nTotalDummyToCreate + " undefined inputs with " + node.sInitializeWith});}, 4000) | ||
} | ||
@@ -173,2 +172,7 @@ } | ||
function setNodeStatus({fill, shape, text}) | ||
{ | ||
node.status({fill: fill,shape: shape,text: text + " (Last " + new Date().toLocaleString() + ")"}) | ||
} | ||
function CalculateResult(_operation) { | ||
@@ -244,14 +248,4 @@ var res; | ||
function DisplayUnkownStatus () { | ||
node.status( | ||
{ | ||
fill: "gray", | ||
shape: "ring", | ||
text: "Reset due to unexpected new topic" | ||
}); | ||
}; | ||
function SetResult(_valueAND, _valueOR, _valueXOR, optionalTopic) { | ||
node.status({fill: "green",shape: "dot",text: "(AND)" + _valueAND + " (OR)" +_valueOR + " (XOR)" +_valueXOR}); | ||
setNodeStatus({fill: "green",shape: "dot",text: "(AND)" + _valueAND + " (OR)" +_valueOR + " (XOR)" +_valueXOR}); | ||
@@ -258,0 +252,0 @@ if (_valueAND!=null){ |
@@ -6,3 +6,3 @@ module.exports = function(RED) { | ||
var node = this; | ||
node.status( {fill: "grey" ,shape: "dot" ,text: "Waiting"}); | ||
setNodeStatus( {fill: "grey" ,shape: "dot" ,text: "Waiting"}); | ||
this.on('input', function (msg) { | ||
@@ -26,7 +26,7 @@ var sTopic = node.config.name; | ||
if (bRes === true) { | ||
node.status( {fill: "green" ,shape: "dot" ,text: "(Send) true,null"}); | ||
setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) true,null"}); | ||
node.send([msgTrue, null]); | ||
} else | ||
{ | ||
node.status( {fill: "green" ,shape: "dot" ,text: "(Send) null,false"}); | ||
setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) null,false"}); | ||
node.send([null, msgFalse]); | ||
@@ -38,3 +38,7 @@ } | ||
function setNodeStatus({fill, shape, text}) | ||
{ | ||
node.status({fill: fill,shape: shape,text: text + " (Last " + new Date().toLocaleString() + ")"}) | ||
} | ||
@@ -62,4 +66,4 @@ function ToBoolean( value ) { | ||
RED.nodes.registerType("FilterUltimate",FilterUltimate); | ||
} |
@@ -7,3 +7,3 @@ module.exports = function(RED) { | ||
var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/ | ||
node.status( {fill: "grey" ,shape: "dot" ,text: "waiting"}); | ||
setNodeStatus( {fill: "grey" ,shape: "dot" ,text: "Waiting"}); | ||
@@ -14,3 +14,3 @@ this.on('input', function(msg) { | ||
if (topic !== undefined && payload !== undefined) { | ||
node.status( {fill: "green" ,shape: "dot" ,text: !ToBoolean(payload)}); | ||
setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) " + !ToBoolean(payload)}); | ||
node.send({ topic: topic, payload: !ToBoolean(payload) }); | ||
@@ -42,6 +42,13 @@ return; | ||
}; | ||
} | ||
function setNodeStatus({fill, shape, text}) | ||
{ | ||
node.status({fill: fill,shape: shape,text: text + " (Last " + new Date().toLocaleString() + ")"}) | ||
} | ||
} | ||
RED.nodes.registerType("InvertUltimate",InvertUltimate); | ||
} |
# node-red-contrib-boolean-logic-ultimate | ||
<p> | ||
<b>Version 1.0.5</b><br/> | ||
- Added the Last value change date/time in the status.<br/> | ||
- Correction in the in-line help<br/> | ||
- Better format of the README.md<br/> | ||
</p> | ||
<p> | ||
<b>Version 1.0.4</b><br/> | ||
@@ -4,0 +10,0 @@ - Added the option to initialize the undefined inputs with true or false. Thanks to this, the node is immediately operative (will not wait until all topis arrives).<br/> |
{ | ||
"name": "node-red-contrib-boolean-logic-ultimate", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A set of Node-RED enhanced boolean logic, with persisten values after reboot and more", | ||
@@ -5,0 +5,0 @@ "author": "Supergiovane (https://github.com/Supergiovane)", |
@@ -32,3 +32,4 @@ # node-red-contrib-boolean-logic-ultimate | ||
<br/> | ||
<b>Filter output result</b><br /> | ||
***Filter output result*** | ||
<ol> | ||
@@ -63,6 +64,2 @@ <li>Output both 'true' and 'false' results: Standard behaviour, the node will output <b>true</b> and <b>false</b> whenever it receives an input and calculate the boolean logics as output.</li> | ||
Example of trigger mode = Single topic + eval other inputs | ||
```js | ||
[{"id":"4d2e4d1.4a02034","type":"BooleanLogicUltimate","z":"5635003e.2d70f","name":"","filtertrue":"both","persist":true,"triggertopic":"MotionSensor","outputtriggeredby":"onlyonetopic","inputCount":"3","topic":"result","x":460,"y":580,"wires":[["a9e93fa0.99508"],[],[]]},{"id":"b3a4633e.ff06c","type":"inject","z":"5635003e.2d70f","name":"","topic":"MotionSensor","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":560,"wires":[["4d2e4d1.4a02034"]]},{"id":"150ff8fd.8110e7","type":"inject","z":"5635003e.2d70f","name":"","topic":"Dusk","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":760,"wires":[["4d2e4d1.4a02034"]]},{"id":"6ecd73e1.9ac75c","type":"inject","z":"5635003e.2d70f","name":"","topic":"Rain","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":660,"wires":[["4d2e4d1.4a02034"]]},{"id":"350fb477.b0d484","type":"inject","z":"5635003e.2d70f","name":"","topic":"Dusk","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":800,"wires":[["4d2e4d1.4a02034"]]},{"id":"1118f46a.b967ac","type":"inject","z":"5635003e.2d70f","name":"","topic":"MotionSensor","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":600,"wires":[["4d2e4d1.4a02034"]]},{"id":"4e793dec.646b4c","type":"inject","z":"5635003e.2d70f","name":"","topic":"Rain","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":700,"wires":[["4d2e4d1.4a02034"]]},{"id":"a9e93fa0.99508","type":"debug","z":"5635003e.2d70f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":650,"y":580,"wires":[]},{"id":"8d44deef.e81d","type":"comment","z":"5635003e.2d70f","name":"Switch on the light only when it's raining and it's dusk. The trigger is someone entering in the Motion Sensor's area.","info":"Triggers only if someone enters \nin the motion sensor's area","x":410,"y":520,"wires":[]}] | ||
``` | ||
@@ -69,0 +66,0 @@ <br/><br/> |
Sorry, the diff of this file is not supported yet
324
0.93%33262
-5.16%100
-2.91%