@parallaxcontrol/node-red-control
Version:
A comprehensive package of Node-RED nodes designed to seamlessly integrate with the Parallax Control Engine, offering enhanced control capabilities for AV Automation.
49 lines (39 loc) • 1.9 kB
JavaScript
module.exports = function(RED) {
function ClearSignalStateNode(config) {
RED.nodes.createNode(this, config);
var node = this;
this.dataType = config.dataType;
node.on('input', function(msg) {
if (!node.dataType) {
node.warn("Warning in Node: " + node.id + ", check node status for more information.");
node.status({ fill: "red", shape: "ring", text: "DataType is undefined: " + node.dataType });
var message = { Value : false };
node.send({payload:message});
}
var dictionary = node.context().global.get(node.dataType);
if (!dictionary) {
node.status({ fill: "red", shape: "ring", text: "The dictionary is empty: " + node.dataType });
var message = { Value : false };
node.send({payload:message});
}
try {
for (var entry in dictionary) {
if (dictionary.hasOwnProperty(entry)) {
var value = dictionary[entry];
this.context().global.set(node.dataType,null);
node.status({ fill: "blue", shape: "dot", text: "Clearing Data for: " + node.dataType });
var message = { Value : true };
node.send({payload:message});
}
}
} catch (Error) {
node.warn("Warning in Node: " + node.id + ", check node status for more information.");
node.status({ fill: "red", shape: "ring", text: "Error: " + Error });
var message = { Value : false };
node.send({payload:message});
}
return msg;
});
}
RED.nodes.registerType("clear-signal-state", ClearSignalStateNode);
}