Added Content
This commit is contained in:
29
mqtt-domo-in/miRGBConv.js
Normal file
29
mqtt-domo-in/miRGBConv.js
Normal file
@@ -0,0 +1,29 @@
|
||||
module.exports = function(RED) {
|
||||
function mqttdomoinrgb(config) {
|
||||
RED.nodes.createNode(this,config);
|
||||
this.idx = config.idx;
|
||||
this.Savetocontex = config.Savetocontex;
|
||||
var flowContext = this.context().flow;
|
||||
var node = this;
|
||||
node.on('input', function(msg) {
|
||||
var r = msg.payload.Color.r;
|
||||
var g = msg.payload.Color.g;
|
||||
var b = msg.payload.Color.b;
|
||||
function componentToHex(c) {
|
||||
var hex = c.toString(16);
|
||||
return hex.length == 1 ? "0" + hex : hex;
|
||||
}
|
||||
msg.payload = "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
||||
node.send(msg);
|
||||
|
||||
if (node.Savetocontex === true) {
|
||||
if (node.idx === 'undefined' || node.idx === null || node.idx === "" ) {
|
||||
node.warn("IDX not set");
|
||||
} else{
|
||||
flowContext.set(node.idx + "-color", msg.payload)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mqtt-domo-in-rgb",mqttdomoinrgb);
|
||||
}
|
||||
Reference in New Issue
Block a user