UNPKG

node-red-contrib-blynk-ws

Version:

Node Red integration with Blynk App and Server through websockets

65 lines (59 loc) 1.8 kB
module.exports = (RED) => { function BlynkInReadNode(n) { RED.nodes.createNode(this, n); this.client = n.client; const node = this; this.blynkClient = RED.nodes.getNode(this.client); this.nodeType = 'read'; this.pin = n.pin; this.pin_all = n.pin_all; if (this.pin_all) this.connected_label = RED._('blynk-ws-in-read.status.connected-all'); else this.connected_label = RED._('blynk-ws-in-read.status.connected-fixed') + this.pin; if (this.blynkClient) { this.blynkClient.registerInputNode(this); this.blynkClient.on('opened', (n) => { // eslint-disable-line no-shadow node.status({ fill: 'yellow', shape: 'dot', text: RED._('blynk-ws-in-read.status.connecting') + n, }); }); this.blynkClient.on('connected', () => { node.status({ fill: 'green', shape: 'dot', text: node.connected_label, }); }); this.blynkClient.on('error', () => { node.status({ fill: 'red', shape: 'ring', text: 'blynk-ws-in-read.status.error', }); }); this.blynkClient.on('closed', () => { node.status({ fill: 'red', shape: 'ring', text: 'blynk-ws-in-read.status.disconnected', }); }); this.blynkClient.on('disabled', () => { node.status({ fill: 'red', shape: 'dot', text: 'blynk-ws-in-read.status.disabled', }); }); } else { this.error(RED._('blynk-ws-in-read.errors.missing-conf')); } this.on('close', () => { if (node.blynkClient) { node.blynkClient.removeInputNode(node); } }); } RED.nodes.registerType('blynk-ws-in-read', BlynkInReadNode); };