node-red-contrib-boolean-logic-ultimate
Advanced tools
Comparing version
@@ -5,7 +5,10 @@ module.exports = function (RED) { | ||
var node = this; | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/ | ||
node.config = config; | ||
node.jSonStates = {}; // JSON object with elements. It's not an array! Format: {"Rain":true,"Dusk":true,"MotionSensor":true} | ||
node.jSonStates = {}; // JSON object containing the states. | ||
node.sInitializeWith = typeof node.config.sInitializeWith === "undefined" ? "WaitForPayload" : node.config.sInitializeWith; | ||
var fs = require('fs'); | ||
var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/ | ||
node.persistPath = path.join(RED.settings.userDir, "booleanlogicultimatepersist"); // 26/10/2020 Contains the path for the states dir. | ||
@@ -19,3 +22,3 @@ // Helper for the config html, to be able to delete the peristent states file | ||
try { | ||
if (fs.existsSync("states/" + _nodeid.toString())) fs.unlinkSync("states/" + _nodeid.toString()); | ||
if (fs.existsSync(path.join(node.persistPath, _nodeid.toString()))) fs.unlinkSync(path.join(node.persistPath, _nodeid.toString())); | ||
} catch (error) { | ||
@@ -26,6 +29,22 @@ } | ||
// 26/10/2020 Check for path and create it if doens't exists | ||
if (!fs.existsSync(node.persistPath)) { | ||
// Create the path | ||
try { | ||
fs.mkdirSync(node.persistPath); | ||
// Backward compatibility: Copy old states dir into the new folder | ||
if (fs.existsSync("states")) { | ||
var filenames = fs.readdirSync("states"); | ||
filenames.forEach(file => { | ||
RED.log.info("BooleanLogicUltimate: migrating from old states path to the new persist " + file); | ||
fs.copyFileSync("states/" + file, path.join(node.persistPath, path.basename(file))); | ||
}); | ||
} | ||
} catch (error) { } | ||
} | ||
// Populate the state array with the persisten file | ||
if (node.config.persist == true) { | ||
try { | ||
var contents = fs.readFileSync("states/" + node.id.toString()).toString(); | ||
var contents = fs.readFileSync(path.join(node.persistPath, node.id.toString())).toString(); | ||
if (typeof contents !== 'undefined') { | ||
@@ -86,5 +105,3 @@ node.jSonStates = JSON.parse(contents); | ||
try { | ||
if (!fs.existsSync("states")) fs.mkdirSync("states"); | ||
fs.writeFileSync("states/" + node.id.toString(), JSON.stringify(node.jSonStates)); | ||
fs.writeFileSync(path.join(node.persistPath, node.id.toString()), JSON.stringify(node.jSonStates)); | ||
} catch (error) { | ||
@@ -147,3 +164,3 @@ setNodeStatus({ fill: "red", shape: "dot", text: "Node cannot write to filesystem: " + error }); | ||
try { | ||
if (fs.existsSync("states/" + node.id.toString())) fs.unlinkSync("states/" + node.id.toString()); | ||
if (fs.existsSync(path.join(node.persistPath, node.id.toString()))) fs.unlinkSync(path.join(node.persistPath, node.id.toString())); | ||
setNodeStatus({ fill: "red", shape: "ring", text: "Persistent states deleted (" + node.id.toString() + ")." }); | ||
@@ -150,0 +167,0 @@ } catch (error) { |
@@ -7,2 +7,8 @@ # node-red-contrib-boolean-logic-ultimate | ||
<p> | ||
<b>Version 1.0.21</b> October 2020<br/> | ||
- Changed the way to handle the presistent states. This allow the node to correctly save the states in non standard node-red installations (docker, home-assistant plugin etc). Thanks @Botched1 for raising the issue.</br> | ||
- Automatic migration of persistens states from the old to the new path.</br> | ||
- Moved the inject node in the "common" node-red group. | ||
</p> | ||
<p> | ||
<b>Version 1.0.20</b> August 2020<br/> | ||
@@ -9,0 +15,0 @@ - NEW: Inject Node. The pourpose of this node is to speed up the testing of you flow, by issuing true/false command by pushbutton on the node itself. This node is simpler as the default node-red inject node.</br> |
{ | ||
"name": "node-red-contrib-boolean-logic-ultimate", | ||
"version": "1.0.20", | ||
"version": "1.0.21", | ||
"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.", | ||
"author": "Supergiovane (https://github.com/Supergiovane)", | ||
"dependencies": { | ||
"fs": "0.0.1-security" | ||
"fs": "0.0.1-security", | ||
"path": ">=0.12.7" | ||
}, | ||
@@ -30,5 +31,4 @@ "keywords": [ | ||
"InjectUltimate": "boolean-logic-ultimate/InjectUltimate.js" | ||
} | ||
} | ||
} |
@@ -28,3 +28,3 @@ # node-red-contrib-boolean-logic-ultimate | ||
<code> | ||
[{"id":"1a90a718.5c0409","type":"BooleanLogicUltimate","z":"adb2ee5c.0bf6e","name":"","filtertrue":"both","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"result","x":380,"y":160,"wires":[["5f9fbfcc.d2c34"],[],[]]},{"id":"81ef6fec.5d413","type":"inject","z":"adb2ee5c.0bf6e","name":"Night","topic":"Dark","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["1a90a718.5c0409"]]},{"id":"e0d5d620.966478","type":"inject","z":"adb2ee5c.0bf6e","name":"Daylight","topic":"Dark","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":140,"wires":[["1a90a718.5c0409"]]},{"id":"1c2f8e73.2c22ba","type":"inject","z":"adb2ee5c.0bf6e","name":"Motion detect true","topic":"Motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["1a90a718.5c0409"]]},{"id":"5f9fbfcc.d2c34","type":"debug","z":"adb2ee5c.0bf6e","name":"Garden Light","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":160,"wires":[]},{"id":"201baa3d.7c63ae","type":"inject","z":"adb2ee5c.0bf6e","name":"Motion detect false","topic":"Motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["1a90a718.5c0409"]]},{"id":"b65f4ff4.bfe2c8","type":"comment","z":"adb2ee5c.0bf6e","name":"Motion sensor turns on lights, when it's dark. The light turns off itself at day","info":"","x":290,"y":100,"wires":[]}] | ||
[{"id":"1a90a718.5c0409","type":"BooleanLogicUltimate","z":"adb2ee5c.0bf6e","name":"","filtertrue":"both","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"result","x":380,"y":160,"wires":[["5f9fbfcc.d2c34"],[],[]]},{"id":"81ef6fec.5d413","type":"inject","z":"adb2ee5c.0bf6e","name":"Night","topic":"Dark","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["1a90a718.5c0409"]]},{"id":"e0d5d620.966478","type":"inject","z":"adb2ee5c.0bf6e","name":"Daylight","topic":"Dark","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":140,"wires":[["1a90a718.5c0409"]]},{"id":"1c2f8e73.2c22ba","type":"inject","z":"adb2ee5c.0bf6e","name":"Motion detect true","topic":"Motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["1a90a718.5c0409"]]},{"id":"5f9fbfcc.d2c34","type":"debug","z":"adb2ee5c.0bf6e","name":"Garden Light","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":160,"wires":[]},{"id":"201baa3d.7c63ae","type":"inject","z":"adb2ee5c.0bf6e","name":"Motion detect false","topic":"Motion","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["1a90a718.5c0409"]]},{"id":"b65f4ff4.bfe2c8","type":"comment","z":"adb2ee5c.0bf6e","name":"Motion sensor turns on lights, when it's dark. The light turns off itself at day","info":"","x":290,"y":100,"wires":[]}] | ||
</code> | ||
@@ -31,0 +31,0 @@ </details> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
541751
20.38%28
3.7%543
3.04%2
100%+ Added
+ Added
+ Added
+ Added
+ Added