@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.
98 lines (88 loc) • 4.13 kB
JavaScript
/*
* Copyright (c) 2025 Parallax AV Design Inc.
* All rights reserved.
*
* This software is licensed, not sold. You may not copy, modify, merge,
* publish, distribute, sublicense, or sell copies of this file or substantial
* portions of it except as expressly permitted by the LICENSE file included
* with this package. Use is restricted to building manifests for the
* Parallax Control Node-RED nodes. See LICENSE for details.
*/
module.exports = function(RED) {
function SendSingleDictionaryNode(config) {
RED.nodes.createNode(this, config);
var node = this;
this.joinID = config.joinID;
this.dictionaryKey = config.key;
this.dictionaryType = config.dictionaryType;
// Get the values of the environment variables
var sig;
var errorFlag;
node.on('input', function(msg) {
switch(node.dictionaryType)
{
case "digital":
{
if(typeof msg.payload === "boolean")
{
sig = "DIGITAL_DICTIONARY";
node.status({ fill: "blue", shape: "dot", text: "SigType: " + sig + ", JoinID: " + node.joinID });
}
else {
node.status({ fill: "red", shape: "ring", text: "msg.payload of type Boolean expected, received: " + msg.payload + " check input or select correct SigType." });
errorFlag = true;
}
}
break;
case "analog":
{
if (typeof msg.payload === "number") {
sig = "ANALOG_DICTIONARY";
node.status({ fill: "blue", shape: "dot", text: "SigType: " + sig + ", JoinID: " + node.joinID });
}
else {
node.status({ fill: "red", shape: "ring", text: "msg.payload of type Number expected, received: " + msg.payload + " check input or select correct SigType." });
errorFlag = true;
}
break;
}
case "serial":
{
if (typeof msg.payload === "string") {
sig = "SERIAL_DICTIONARY";
node.status({ fill: "blue", shape: "dot", text: "SigType: " + sig + ", JoinID: " + node.joinID });
}
else {
node.status({ fill: "red", shape: "ring", text: "msg.payload of type String expected, received: " + msg.payload + " of type: " + typeof (msg.payload) + ", check input or select correct SigType." });
errorFlag = true;
}
break;
}
}
if (errorFlag) {
node.warn("Warning in Node: " + node.id + ", check node status for more information.");
return null;
}
else{
if (node.joinID !== "" && node.dictionaryType !== undefined) {
// Construct the dictionary for payload
var dictionary = {};
dictionary[node.dictionaryKey] = msg.payload;
// Set the message payload based on the requirements
var message = {
"Type": sig,
"JoinID": node.joinID,
"Value": dictionary
};
node.send({payload : message});
}
else
{
var errorMsg = { payload: "One or both of the environment variables (JoinID) are not defined." };
node.send(errorMsg);
}
}
});
}
RED.nodes.registerType("send-single-dictionary", SendSingleDictionaryNode);
}