diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index 8c55e3a0c..d41d3b574 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -875,6 +875,11 @@ class HomeAssistant extends Extension { } async publishDeviceTriggerDiscover(entity, key, value, force=false) { + if (entity.settings.hasOwnProperty('homeassistant') && + (entity.settings.homeassistant == null || entity.settings.homeassistant.device_automation == null)) { + return; + } + const device = entity.device; if (!this.discoveredTriggers[device.ieeeAddr]) { this.discoveredTriggers[device.ieeeAddr] = new Set(); diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index bc3219b9d..b4da59211 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -1256,6 +1256,28 @@ describe('HomeAssistant extension', () => { expect(MQTT.publish).toHaveBeenCalledWith('homeassistant/device_automation/0x0017880104e45520/action_double/config', expect.any(String), expect.any(Object), expect.any(Function)); }); + it('Should not discover device_automtation when disabled', async () => { + settings.set(['device_options'], { + homeassistant: {device_automation: null}, + }) + controller = new Controller(false); + await controller.start(); + await flushPromises(); + MQTT.publish.mockClear(); + + const device = zigbeeHerdsman.devices.WXKG11LM; + const payload1 = {data: {onOff: 1}, cluster: 'genOnOff', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10}; + await zigbeeHerdsman.events.message(payload1); + await flushPromises(); + + expect(MQTT.publish).not.toHaveBeenCalledWith( + 'homeassistant/device_automation/0x0017880104e45520/action_single/config', + expect.any(String), + expect.any(Object), + expect.any(Function), + ); + }); + it('Should not discover sensor_click when legacy: false is set', async () => { settings.set(['devices', '0x0017880104e45520'], { legacy: false,