node-red-contrib-xmihome
Version:
Node-RED nodes for controlling Xiaomi Mi Home devices using the xmihome library.
2 lines (1 loc) • 955 B
JavaScript
class l{#b;#h;settings;constructor(b,j,h){this.#b=b,this.#h=j;let k=h.nodes.getNode(this.#h.settings);if(k)this.settings=k.instance;else this.#b.warn("Config node not found or configured.");this.#b.on("input",this.#j.bind(this))}async#j(b,j,h){try{if(!this.settings)throw new Error("Client is not initialized. Check configuration.");if(this.#b.status({fill:"blue",shape:"dot",text:"Refreshing..."}),b.payload=await this.settings.getDevices(!0,this.#h.timeout),Array.isArray(b.payload)&&b.payload.length>0)this.#b.status({fill:"green",shape:"dot",text:`Devices: ${b.payload.length}`});else this.#b.status({fill:"yellow",shape:"ring",text:"No devices"});j(b),h()}catch(k){this.#b.error(`Failed to get devices: ${k.message}`,b),this.#b.status({fill:"red",shape:"ring",text:"Error"}),h(k)}}}function q(b){b.nodes.registerType("xmihome-devices",function(j){b.nodes.createNode(this,j);let h=this;h.instance=new l(h,j,b)})}export{q as default,l as DevicesNode};