diff --git a/lib/controller.js b/lib/controller.js index fa3647f62..91c20b491 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -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') { diff --git a/lib/extension/bridge.js b/lib/extension/bridge.js index 5006f077c..3b21f2324 100644 --- a/lib/extension/bridge.js +++ b/lib/extension/bridge.js @@ -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(); } } diff --git a/lib/zigbee.js b/lib/zigbee.js index 2c6dec582..6f3eeb490 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -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)); diff --git a/test/bridge.test.js b/test/bridge.test.js index ab29fe095..a0074fa32 100644 --- a/test/bridge.test.js +++ b/test/bridge.test.js @@ -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});