mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-28 05:24:29 +00:00
Don't rediscover Home Assistant device_automation (triggers). #4452
This commit is contained in:
@@ -2440,7 +2440,7 @@ class HomeAssistant extends Extension {
|
||||
const discoveryMatch = topic.match(discoveryRegex);
|
||||
const isDeviceAutomation = discoveryMatch && discoveryMatch[1] === 'device_automation';
|
||||
if (discoveryMatch) {
|
||||
// Clear outdated discovery configs.
|
||||
// Clear outdated discovery configs and remember already discoverd device_automations
|
||||
try {
|
||||
message = JSON.parse(message);
|
||||
const property = isDeviceAutomation ? 'topic' : 'availability_topic';
|
||||
@@ -2457,6 +2457,13 @@ class HomeAssistant extends Extension {
|
||||
const resolvedEntity = this.zigbee.resolveEntity(ieeeAddr);
|
||||
let clear = !resolvedEntity || !resolvedEntity.definition;
|
||||
|
||||
if (isDeviceAutomation) {
|
||||
if (!this.discoveredTriggers[ieeeAddr]) {
|
||||
this.discoveredTriggers[ieeeAddr] = new Set();
|
||||
}
|
||||
this.discoveredTriggers[ieeeAddr].add(discoveryMatch[3]);
|
||||
}
|
||||
|
||||
if (!clear && !isDeviceAutomation) {
|
||||
const type = discoveryMatch[1];
|
||||
const objectID = discoveryMatch[3];
|
||||
|
||||
@@ -927,8 +927,8 @@ describe('HomeAssistant extension', () => {
|
||||
MQTT.publish.mockClear();
|
||||
|
||||
const device = zigbeeHerdsman.devices.WXKG11LM;
|
||||
const payload = {data: {onOff: 1}, cluster: 'genOnOff', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10};
|
||||
await zigbeeHerdsman.events.message(payload);
|
||||
const payload1 = {data: {onOff: 1}, cluster: 'genOnOff', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10};
|
||||
await zigbeeHerdsman.events.message(payload1);
|
||||
await flushPromises();
|
||||
|
||||
const discoverPayloadAction = {
|
||||
@@ -1016,7 +1016,7 @@ describe('HomeAssistant extension', () => {
|
||||
|
||||
// Should only discover it once
|
||||
MQTT.publish.mockClear();
|
||||
await zigbeeHerdsman.events.message(payload);
|
||||
await zigbeeHerdsman.events.message(payload1);
|
||||
await flushPromises();
|
||||
expect(MQTT.publish).not.toHaveBeenCalledWith(
|
||||
'homeassistant/device_automation/0x0017880104e45520/action_single/config',
|
||||
@@ -1045,6 +1045,15 @@ describe('HomeAssistant extension', () => {
|
||||
{ retain: false, qos: 0 },
|
||||
expect.any(Function),
|
||||
);
|
||||
|
||||
// Shouldn't rediscover when already discovered in previous session
|
||||
await MQTT.events.message('homeassistant/device_automation/0x0017880104e45520/click_double/config', stringify({topic: 'zigbee2mqtt/0x0017880104e45520/action'}));
|
||||
await flushPromises();
|
||||
MQTT.publish.mockClear();
|
||||
const payload2 = {data: {'32768': 2}, cluster: 'genOnOff', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10};
|
||||
await zigbeeHerdsman.events.message(payload2);
|
||||
await flushPromises();
|
||||
expect(MQTT.publish).not.toHaveBeenCalledWith('homeassistant/device_automation/0x0017880104e45520/click_double/config', expect.any(String), expect.any(Object), expect.any(Function));
|
||||
});
|
||||
|
||||
it('Should not discover sensor_click when legacy: false is set', async () => {
|
||||
|
||||
Reference in New Issue
Block a user