mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-27 21:20:03 +00:00
fix: Fix duplicate action publish when advanced.output has attribute (#25963)
This commit is contained in:
@@ -1294,7 +1294,7 @@ export default class HomeAssistant extends Extension {
|
||||
* Whenever a device publish an {action: *} we discover an MQTT device trigger sensor
|
||||
* and republish it to zigbee2mqtt/my_device/action
|
||||
*/
|
||||
if (entity.isDevice() && entity.definition && data.message.action) {
|
||||
if (settings.get().advanced.output === 'json' && entity.isDevice() && entity.definition && data.message.action) {
|
||||
const value = data.message['action'].toString();
|
||||
await this.publishDeviceTriggerDiscover(entity, 'action', value);
|
||||
await this.mqtt.publish(`${data.entity.name}/action`, value, {});
|
||||
|
||||
@@ -1724,8 +1724,6 @@ describe('Extension: HomeAssistant', () => {
|
||||
{retain: true, qos: 1},
|
||||
);
|
||||
|
||||
expect(mockMQTTPublishAsync).toHaveBeenCalledWith('zigbee2mqtt/button/action', 'single', {retain: false, qos: 0});
|
||||
|
||||
expect(mockMQTTPublishAsync).toHaveBeenCalledWith(
|
||||
'zigbee2mqtt/button',
|
||||
stringify({
|
||||
@@ -1749,8 +1747,6 @@ describe('Extension: HomeAssistant', () => {
|
||||
{retain: true, qos: 1},
|
||||
);
|
||||
|
||||
expect(mockMQTTPublishAsync).toHaveBeenCalledWith('zigbee2mqtt/button/action', 'single', {retain: false, qos: 0});
|
||||
|
||||
// Shouldn't rediscover when already discovered in previous session
|
||||
clearDiscoveredTrigger('0x0017880104e45520');
|
||||
await mockMQTTEvents.message(
|
||||
@@ -1789,6 +1785,19 @@ describe('Extension: HomeAssistant', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test.each(['attribute_and_json', 'json', 'attribute'])('Should publish /action for MQTT device trigger', async (output) => {
|
||||
settings.set(['advanced', 'output'], output);
|
||||
mockMQTTPublishAsync.mockClear();
|
||||
|
||||
const device = devices.WXKG11LM;
|
||||
const payload1 = {data: {onOff: 1}, cluster: 'genOnOff', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10};
|
||||
await mockZHEvents.message(payload1);
|
||||
await flushPromises();
|
||||
|
||||
expect(mockMQTTPublishAsync).toHaveBeenCalledWith('zigbee2mqtt/button/action', 'single', {retain: false, qos: 0});
|
||||
expect(mockMQTTPublishAsync.mock.calls.filter((c) => c[1] === 'single')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('Should not discover device_automation when disabled', async () => {
|
||||
settings.set(['device_options'], {
|
||||
homeassistant: {device_automation: null},
|
||||
|
||||
Reference in New Issue
Block a user