mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 10:58:31 -07:00
30 lines
897 B
JavaScript
30 lines
897 B
JavaScript
const utils = require('../util/utils');
|
|
|
|
/**
|
|
* This extensions marks Xiaomi devices as online.
|
|
*/
|
|
class MarkOnlineXiaomi {
|
|
constructor(zigbee, mqtt, state, publishEntityState) {
|
|
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;
|