Republish devices when network address changes. https://github.com/Koenkk/zigbee2mqtt/discussions/7603

This commit is contained in:
Koen Kanters committed 2021-05-29 15:06:14 +02:00
1 parent 3d00338bc8
commit fff76e6013
4 files changed
+18 -1

No files matched your search

+2
View File
@@ -252,6 +252,8 @@ class Controller {
}
} else if (type === 'deviceAnnounce') {
logger.debug(`Device '${name}' announced itself`);
} else if (type === 'deviceNetworkAddressChanged') {
logger.debug(`Device '${name}' changed network address`);
} else {
/* istanbul ignore else */
if (type === 'deviceLeave') {
+2 -1
View File
@@ -131,7 +131,8 @@ class Bridge extends Extension {
);
}
if ('deviceLeave' === type || ('deviceInterview' === type && data.status !== 'started')) {
if ('deviceLeave' === type || ('deviceInterview' === type && data.status !== 'started') ||
'deviceNetworkAddressChanged' === type) {
await this.publishDevices();
}
}
+2
View File
@@ -70,6 +70,8 @@ class Zigbee extends events.EventEmitter {
}
this.herdsman.on('adapterDisconnected', () => this.emit('adapterDisconnected'));
this.herdsman.on('deviceNetworkAddressChanged', (data) =>
this.emit('event', 'deviceNetworkAddressChanged', data));
this.herdsman.on('deviceAnnounce', (data) => this.emit('event', 'deviceAnnounce', data));
this.herdsman.on('deviceInterview', (data) => this.emit('event', 'deviceInterview', data));
this.herdsman.on('deviceJoined', (data) => this.emit('event', 'deviceJoined', data));
+12
View File
@@ -106,6 +106,18 @@ describe('Bridge', () => {
);
});
it('Should publish event when device joined', async () => {
MQTT.publish.mockClear();
await zigbeeHerdsman.events.deviceNetworkAddressChanged({device: zigbeeHerdsman.devices.bulb});
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/devices',
expect.any(String),
{ retain: true, qos: 0 },
expect.any(Function)
);
});
it('Should publish event when device announces', async () => {
MQTT.publish.mockClear();
await zigbeeHerdsman.events.deviceAnnounce({device: zigbeeHerdsman.devices.bulb});