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.

33 lines (29 loc) 1.1 kB
import { Red } from "node-red"; import * as YeelightSearch from 'yeelight-wifi'; import { Constants } from "../constants"; export class Searcher { static _bulbs:any[] = []; static discover(RED:Red) { new Promise(() => { (new YeelightSearch()).on('found', (bulb:any) => { 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.NODES_PREFIX}-yeelight configurator`) === 0) { let tmpNodeInst = <any> RED.nodes.getNode(tmpNode.id); if(tmpNodeInst.ip === bulb.hostname || tmpNodeInst.sid === parseInt(bulb.id)) { tmpNodeInst.setBulb(bulb); } } }); }); }); } static get bulbs() { return this._bulbs; } }