UNPKG

@george.talusan/node-red-contrib-eufy-robovac

Version:

Node RED plugin wrapper around [eufy-robovac-js](https://github.com/gtalusan/eufy-robovac-js).

49 lines (39 loc) 1.18 kB
const { RoboVac } = require('@george.talusan/eufy-robovac-js'); module.exports = (RED) => { class EufyRobovacConfigNode { constructor (config) { RED.nodes.createNode(this, config); this.connected = false; this.reconnect = true; const { ip, deviceId, localKey } = config; this.robovac = new RoboVac({ ip, deviceId, localKey }); this.robovac.on('tuya.connected', () => { this.connected = true; }); this.robovac.on('tuya.disconnected', async () => { this.connected = false; if (!this.reconnect) { return; } const id = setInterval(async () => { try { await this.robovac.connect(); clearInterval(id); } catch (e) { console.error(e); } }, 2000); }); this.robovac.on('error', (error) => { console.error(error); }); this.robovac.initialize(); this.on('close', () => { console.warn('close'); this.reconnect = false; this.robovac.disconnect(); }); } } RED.nodes.registerType('eufy-robovac-config', EufyRobovacConfigNode); };