mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 18:39:09 -07:00
This commit is contained in:
parent
588124b971
commit
d5c6e39e7d
@ -21,6 +21,7 @@ class DeviceAvailabilityHandler {
|
||||
this.availability_timeout = settings.get().advanced.availability_timeout;
|
||||
this.timers = {};
|
||||
this.pending = [];
|
||||
this.state = {};
|
||||
|
||||
/**
|
||||
* Setup command queue.
|
||||
@ -106,6 +107,7 @@ class DeviceAvailabilityHandler {
|
||||
}
|
||||
|
||||
publishAvailability(ieeeAddr, available) {
|
||||
this.state[ieeeAddr] = available;
|
||||
const deviceSettings = settings.getDevice(ieeeAddr);
|
||||
const name = deviceSettings ? deviceSettings.friendly_name : ieeeAddr;
|
||||
const topic = `${name}/availability`;
|
||||
@ -113,35 +115,17 @@ class DeviceAvailabilityHandler {
|
||||
this.mqtt.publish(topic, payload, {retain: true, qos: 0});
|
||||
}
|
||||
|
||||
configure(device, mappedDevice) {
|
||||
const ieeeAddr = device.ieeeAddr;
|
||||
const friendlyName = settings.getDevice(ieeeAddr) ? settings.getDevice(ieeeAddr).friendly_name : 'unknown';
|
||||
logger.debug(`Configuring ${friendlyName} (${ieeeAddr}) ...`);
|
||||
// Call configure function of this device.
|
||||
mappedDevice.configure(ieeeAddr, this.zigbee.shepherd, this.zigbee.getCoordinator(), (ok, msg) => {
|
||||
if (ok) {
|
||||
logger.info(`Succesfully configured ${friendlyName} (${ieeeAddr})`);
|
||||
} else {
|
||||
logger.error(`Failed to configure ${friendlyName} (${ieeeAddr}) ('${msg}')`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onZigbeeMessage(message, device, mappedDevice) {
|
||||
// When a zigbee message from a device is received we know the device is still alive.
|
||||
// => reset the timer.
|
||||
if (device && this.isPingable(this.zigbee.getDevice(device.ieeeAddr))) {
|
||||
// When a message is received and the device is marked as offline, mark it online.
|
||||
if (this.state.hasOwnProperty(device.ieeeAddr) && !this.state[device.ieeeAddr]) {
|
||||
this.publishAvailability(device.ieeeAddr, true);
|
||||
}
|
||||
|
||||
this.setTimer(device.ieeeAddr);
|
||||
}
|
||||
|
||||
if (message.type == 'devIncoming' || message.type == 'endDeviceAnnce') {
|
||||
logger.info('Announcement: Device incoming...');
|
||||
//check device for post announce handler
|
||||
if(device && mappedDevice && mappedDevice.configure) {
|
||||
//logger.info('Announcement: need to re-configure');
|
||||
this.configure(device,mappedDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,31 @@ class DeviceConfigure {
|
||||
|
||||
onZigbeeMessage(message, device, mappedDevice) {
|
||||
if (device && mappedDevice) {
|
||||
// endDeviceAnnce is typically send when a device comes online after being
|
||||
// powered off. In some cases this requires a re-configure of the device.
|
||||
// Mark this device as not configured.
|
||||
// https://github.com/Koenkk/zigbee2mqtt/issues/966
|
||||
if (message.type === 'endDeviceAnnce') {
|
||||
this.mark(device.ieeeAddr, false);
|
||||
}
|
||||
|
||||
this.configure(device, mappedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
mark(ieeeAddr, configured) {
|
||||
if (configured) {
|
||||
if (!this.configured.includes(ieeeAddr)) {
|
||||
this.configured.push(ieeeAddr);
|
||||
}
|
||||
} else {
|
||||
const index = this.configured.indexOf(ieeeAddr);
|
||||
if (index > -1) {
|
||||
this.configured.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configure(device, mappedDevice) {
|
||||
const ieeeAddr = device.ieeeAddr;
|
||||
|
||||
@ -44,7 +65,7 @@ class DeviceConfigure {
|
||||
});
|
||||
|
||||
// Mark as configured
|
||||
this.configured.push(ieeeAddr);
|
||||
this.mark(ieeeAddr, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
npm-shrinkwrap.json
generated
4
npm-shrinkwrap.json
generated
@ -4803,8 +4803,8 @@
|
||||
}
|
||||
},
|
||||
"zigbee-shepherd": {
|
||||
"version": "git+https://github.com/Koenkk/zigbee-shepherd.git#94debb60dfe8b85632708990dfe97913d1474a53",
|
||||
"from": "git+https://github.com/Koenkk/zigbee-shepherd.git#94debb60dfe8b85632708990dfe97913d1474a53",
|
||||
"version": "git+https://github.com/Koenkk/zigbee-shepherd.git#6f06ba01d7dbe13dc5a3b0652cf4ad01debbf188",
|
||||
"from": "git+https://github.com/Koenkk/zigbee-shepherd.git#6f06ba01d7dbe13dc5a3b0652cf4ad01debbf188",
|
||||
"requires": {
|
||||
"areq": "^0.2.0",
|
||||
"busyman": "^0.3.0",
|
||||
|
@ -45,7 +45,7 @@
|
||||
"semver": "*",
|
||||
"winston": "2.4.2",
|
||||
"ziee": "*",
|
||||
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#94debb60dfe8b85632708990dfe97913d1474a53",
|
||||
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#6f06ba01d7dbe13dc5a3b0652cf4ad01debbf188",
|
||||
"zigbee-shepherd-converters": "7.0.27",
|
||||
"zive": "*"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user