34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
module.exports = function(RED) {
|
|
function httpdomooutrgb(config) {
|
|
RED.nodes.createNode(this,config);
|
|
this.idx = parseInt(config.idx, 10);
|
|
var flowContext = this.context().flow;
|
|
var node = this;
|
|
node.on('input', function(msg) {
|
|
if (node.idx === 'undefined' || isNaN(node.idx) || node.idx === null || node.idx === "" ) {
|
|
node.error("IDX not set");
|
|
return;
|
|
}
|
|
var flowbrightness = flowContext.get(node.idx + "-brightness")
|
|
if (flowbrightness === 'undefined' || isNaN(flowbrightness) || flowbrightness === null || flowbrightness === "" ) {
|
|
node.warn("Brightness for this device is not defined in the flow, Setting to 100");
|
|
var curbrightness = 100
|
|
} else {
|
|
var curbrightness = flowbrightness
|
|
}
|
|
|
|
var newcolor = msg.payload;
|
|
msg.payload = {
|
|
"idx": node.idx,
|
|
"hex": newcolor,
|
|
"brightness": curbrightness,
|
|
"type": "command",
|
|
"param": "setcolbrightnessvalue",
|
|
"iswhite": false
|
|
};
|
|
node.send(msg);
|
|
});
|
|
}
|
|
RED.nodes.registerType("http-domo-out-rgb",httpdomooutrgb);
|
|
}
|