node-red-contrib-viera
Version:
Control Panasonic Viera tv with node red
39 lines (34 loc) • 1.26 kB
JavaScript
;
const Viera = require('viera.js');
module.exports = function (RED) {
function VieraReadNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var tv = new Viera(config.host);
node.on('input', function (msg) {
var functionName = config.function || msg.function;
if (typeof (functionName) !== 'undefined') {
return tv[config.function](function (data) {
node.send({
payload: data
});
});
}
RED.log.error(`Function ${functionName} not defined.`);
});
}
RED.nodes.registerType("viera read", VieraReadNode);
function VieraWriteNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var tv = new Viera(config.host);
node.on('input', function (msg) {
var functionName = config.function || msg.function;
if (typeof (functionName) !== 'undefined') {
return tv[config.function](msg.payload);
}
RED.log.error(`Function ${functionName} not defined.`);
});
}
RED.nodes.registerType("viera write", VieraWriteNode);
}