From 997c5d3e44162b59a6d7011607af5e47c71e2df8 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 7 Oct 2019 21:58:35 +0200 Subject: [PATCH] Allow to disable Home Assistant device discovery. https://github.com/Koenkk/zigbee2mqtt/issues/2089 --- lib/extension/homeassistant.js | 3 ++- test/homeassistant.test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index 2d4a978b3..248214ce7 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -963,7 +963,8 @@ class HomeAssistant extends BaseExtension { } const entity = settings.getEntity(entityID); - if (!entity || (entity.type === 'device' && !mapping[mappedModel.model])) { + if (!entity || (entity.type === 'device' && !mapping[mappedModel.model]) || + (entity.hasOwnProperty('homeassistant') && !entity.homeassistant)) { return; } diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index 8c5f067f2..dae806b9a 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -340,6 +340,23 @@ describe('HomeAssistant extension', () => { ); }); + it('Shouldnt discover devices when homeassistant null is set in device options', async () => { + settings.set(['devices', '0x0017880104e45522'], { + homeassistant: null, + friendly_name: 'weather_sensor', + retain: false, + }) + + controller = new Controller(false); + await controller.start(); + + await flushPromises(); + + const topics = MQTT.publish.mock.calls.map((c) => c[0]); + expect(topics).not.toContain('homeassistant/sensor/0x0017880104e45522/humidity/config') + expect(topics).not.toContain('homeassistant/sensor/0x0017880104e45522/temperature/config') + }); + it('Should discover devices with fan', async () => { controller = new Controller(false); await controller.start();