Introduce new ping mechanism (‘basic’) and use it for Xiaomi. https://github.com/Koenkk/zigbee2mqtt/issues/1248

This commit is contained in:
Koen Kanters
2019-03-23 17:45:28 +01:00
parent c64158b75d
commit 008fda4d90
2 changed files with 33 additions and 18 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ class Xiaomi {
}
ping(ieeeAddr) {
this.zigbee.ping(ieeeAddr);
this.zigbee.ping(ieeeAddr, 'error', null, 'basic');
}
handleInterval() {
+32 -17
View File
@@ -275,26 +275,41 @@ class Zigbee {
});
}
ping(ieeeAddr, errorLogLevel='error', cb) {
const device = this.shepherd._findDevByAddr(ieeeAddr);
ping(ieeeAddr, errorLogLevel='error', cb, mechanism='default') {
const callback = (error) => {
if (error) {
logger[errorLogLevel](`Failed to ping ${ieeeAddr}`);
} else {
logger.debug(`Successfully pinged ${ieeeAddr}`);
}
if (device) {
this.queue.push(ieeeAddr, (queueCallback) => {
logger.debug(`Ping ${ieeeAddr}`);
this.shepherd.controller.checkOnline(device, (error) => {
if (error) {
logger[errorLogLevel](`Failed to ping ${ieeeAddr}`);
} else {
logger.debug(`Successfully pinged ${ieeeAddr}`);
}
if (cb) {
cb(error);
}
};
if (cb) {
cb(error);
}
queueCallback(error);
if (mechanism === 'default') {
const device = this.shepherd._findDevByAddr(ieeeAddr);
if (device) {
logger.debug(`Ping ${ieeeAddr} (default)`);
this.queue.push(ieeeAddr, (queueCallback) => {
this.shepherd.controller.checkOnline(device, (error) => {
callback(error);
queueCallback(error);
});
});
});
}
} else if (mechanism === 'basic') {
const endpoint = this.getEndpoint(ieeeAddr, null);
if (endpoint) {
logger.debug(`Ping ${ieeeAddr} (basic)`);
this.queue.push(ieeeAddr, (queueCallback) => {
endpoint.foundation('genBasic', 'read', [{attrId: 0}], (error) => {
callback(error);
queueCallback(error);
});
});
}
}
}