From aac7cb1ff61edcafd1aa19aa00de01afe70236d3 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Thu, 29 Oct 2020 18:03:16 +0100 Subject: [PATCH] Fix brightness or state not read when reading state and brightness. https://github.com/Koenkk/zigbee2mqtt/issues/4803 --- lib/extension/publish.js | 5 +++-- test/publish.test.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/extension/publish.js b/lib/extension/publish.js index 1f80056b..d3becfb5 100644 --- a/lib/extension/publish.js +++ b/lib/extension/publish.js @@ -197,8 +197,9 @@ class EntityPublish extends Extension { if (!usedConverters.hasOwnProperty(endpointOrGroupID)) usedConverters[endpointOrGroupID] = []; const converter = converters.find((c) => c.key.includes(key)); - if (usedConverters[endpointOrGroupID].includes(converter)) { - // Use a converter only once (e.g. light_onoff_brightness converters can convert state and brightness) + if (topic.type === 'set' && usedConverters[endpointOrGroupID].includes(converter)) { + // Use a converter for set only once + // (e.g. light_onoff_brightness converters can convert state and brightness) continue; } diff --git a/test/publish.test.js b/test/publish.test.js index 6d069f45..49f7e03b 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -440,10 +440,11 @@ describe('Publish', () => { it('Should handle get', async () => { const device = zigbeeHerdsman.devices.bulb_color; const endpoint = device.getEndpoint(1); - await MQTT.events.message('zigbee2mqtt/bulb_color/get', stringify({state: ''})); + await MQTT.events.message('zigbee2mqtt/bulb_color/get', stringify({state: '', brightness: ''})); await flushPromises(); - expect(endpoint.read).toHaveBeenCalledTimes(1); + expect(endpoint.read).toHaveBeenCalledTimes(2); expect(endpoint.read).toHaveBeenCalledWith('genOnOff', ['onOff']); + expect(endpoint.read).toHaveBeenCalledWith('genLevelCtrl', ['currentLevel']); }); it('Should handle get with multiple endpoints', async () => {