From d86aa10875bcab9819da5bed14779081b19ccfd0 Mon Sep 17 00:00:00 2001 From: Koenkk Date: Thu, 14 Jun 2018 18:19:54 +0200 Subject: [PATCH] Xiaomi devices: check if exsist. #116 --- lib/zigbee.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/zigbee.js b/lib/zigbee.js index 49cda420a..eee31b990 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -74,12 +74,15 @@ class Zigbee { // to query info from devices (which would fail because they go tosleep). // Xiaomi lumi.plug has manufId === 4447 and can be in the sleep mode too const devices = this.getAllClients(); - devices.forEach((device) => { - if ((device.manufId === 4151) || (device.manufId === 4447)) { - this.shepherd.find(device.ieeeAddr, 1).getDevice().update({ - status: 'online', - joinTime: Math.floor(Date.now() / 1000), - }); + devices.forEach((d) => { + if ((d.manufId === 4151) || (d.manufId === 4447)) { + const device = this.shepherd.find(d.ieeeAddr, 1); + if (device) { + device.getDevice().update({ + status: 'online', + joinTime: Math.floor(Date.now() / 1000), + }); + } } });