zigbee2mqtt/lib/extension/markOnlineXiaomi.js

30 lines
897 B
JavaScript
Raw Normal View History

2018-11-16 12:23:11 -07:00
const utils = require('../util/utils');
/**
* This extensions marks Xiaomi devices as online.
*/
class MarkOnlineXiaomi {
constructor(zigbee, mqtt, state, publishDeviceState) {
this.zigbee = zigbee;
}
onZigbeeStarted() {
// Set all Xiaomi devices to be online, so shepherd won't try
// to query info from devices (which would fail because they go to sleep).
const devices = this.zigbee.getAllClients();
devices.forEach((d) => {
if (utils.isXiaomiDevice(d)) {
const device = this.zigbee.shepherd.find(d.ieeeAddr, 1);
if (device) {
device.getDevice().update({
status: 'online',
joinTime: Math.floor(Date.now() / 1000),
});
}
}
});
}
}
module.exports = MarkOnlineXiaomi;