UNPKG

node-red-contrib-mi-sensors

Version:

A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway, and the Gateway itself.

32 lines (31 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const YeelightSearch = require("yeelight-wifi"); const constants_1 = require("../constants"); class Searcher { static discover(RED) { new Promise(() => { (new YeelightSearch()).on('found', (bulb) => { this._bulbs.push({ name: bulb.name, model: bulb.model, sid: parseInt(bulb.id), ip: bulb.hostname }); RED.nodes.eachNode((tmpNode) => { if (tmpNode.type.indexOf(`${constants_1.Constants.NODES_PREFIX}-yeelight configurator`) === 0) { let tmpNodeInst = RED.nodes.getNode(tmpNode.id); if (tmpNodeInst.ip === bulb.hostname || tmpNodeInst.sid === parseInt(bulb.id)) { tmpNodeInst.setBulb(bulb); } } }); }); }); } static get bulbs() { return this._bulbs; } } Searcher._bulbs = []; exports.Searcher = Searcher;