2018-11-16 12:23:11 -07:00
|
|
|
const utils = require('../util/utils');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This extensions marks Xiaomi devices as online.
|
|
|
|
*/
|
|
|
|
class MarkOnlineXiaomi {
|
2019-02-04 10:36:49 -07:00
|
|
|
constructor(zigbee, mqtt, state, publishEntityState) {
|
2018-11-16 12:23:11 -07:00
|
|
|
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;
|