From b59d761ca63721a9cc3514eda9ab2ac8fc6d4866 Mon Sep 17 00:00:00 2001 From: nightdeveloper Date: Wed, 11 Mar 2020 20:21:06 +0300 Subject: [PATCH] publish announces to log topic (#3101) * publish announces to log topic * publish announces to log topic #test fix * Update controller.js * Update controller.test.js * Update deviceAvailability.test.js Co-authored-by: Andrey Sergeew Co-authored-by: Koen Kanters --- lib/controller.js | 1 + test/controller.test.js | 1 + test/deviceAvailability.test.js | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/controller.js b/lib/controller.js index 395fb506d..2c0c805ae 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -218,6 +218,7 @@ class Controller { } } else if (type === 'deviceAnnounce') { logger.debug(`Device '${name}' announced itself`); + this.mqtt.log('device_announced', 'announce', {friendly_name: name}); } else { /* istanbul ignore else */ if (type === 'deviceLeave') { diff --git a/test/controller.test.js b/test/controller.test.js index 24140becd..27a555d61 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -360,6 +360,7 @@ describe('Controller', () => { await zigbeeHerdsman.events.deviceAnnounce(payload); await flushPromises(); expect(logger.debug).toHaveBeenCalledWith(`Device 'bulb' announced itself`); + expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/bridge/log', '{"type":"device_announced","message":"announce","meta":{"friendly_name":"bulb"}}', { retain: false, qos: 0}, expect.any(Function)); }); it('On zigbee event device leave (removed from database and settings)', async () => { diff --git a/test/deviceAvailability.test.js b/test/deviceAvailability.test.js index b9505b8cf..a2165dc4d 100644 --- a/test/deviceAvailability.test.js +++ b/test/deviceAvailability.test.js @@ -280,7 +280,6 @@ describe('Device availability', () => { expect(device.ping).toHaveBeenCalledTimes(0); MQTT.publish.mockClear(); await zigbeeHerdsman.events.deviceAnnounce({device}); - expect(MQTT.publish).toHaveBeenCalledTimes(0); }); it('Should not read when device has no modelID and reconnects', async () => {