|
|
|
|
|
|
|
|
node.status({fill: "blue",shape: "ring",text: "Loaded persistent states (" + Object.keys(node.state).length + " total)."}); |
|
|
node.status({fill: "blue",shape: "ring",text: "Loaded persistent states (" + Object.keys(node.state).length + " total)."}); |
|
|
} |
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
node.status({fill: "grey",shape: "ring",text: "No persistent states"}); |
|
|
|
|
|
|
|
|
node.status({fill: "grey",shape: "ring",text: "No persistent states: " + error}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sabe the state array to a perisistent file |
|
|
// Sabe the state array to a perisistent file |
|
|
if (this.config.persist == true) { |
|
|
if (this.config.persist == true) { |
|
|
if (!fs.existsSync("states")) fs.mkdirSync("states"); |
|
|
|
|
|
fs.writeFileSync("states/" + node.id.toString(),JSON.stringify(state)); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
if (!fs.existsSync("states")) fs.mkdirSync("states"); |
|
|
|
|
|
fs.writeFileSync("states/" + node.id.toString(),JSON.stringify(state)); |
|
|
|
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
node.status({fill: "red",shape: "dot",text: "Node cannot write to filesystem: " + error}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Do we have as many inputs as we expect? |
|
|
// Do we have as many inputs as we expect? |