From 1f39ff6f577f036cf15704735cd19070cbeefaee Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 19 Jul 2020 00:04:39 +0200 Subject: [PATCH] Fix transition from device_options not applied. #3922 --- lib/extension/publish.js | 4 ++-- test/publish.test.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/extension/publish.js b/lib/extension/publish.js index 02e0bcc6..39eb33d6 100644 --- a/lib/extension/publish.js +++ b/lib/extension/publish.js @@ -91,11 +91,11 @@ class EntityPublish extends Extension { definition = resolvedEntity.definition; target = resolvedEntity.endpoint; converters = resolvedEntity.definition.toZigbee; - options = resolvedEntity.settings; + options = {...settings.get().device_options, ...resolvedEntity.settings}; } else { converters = groupConverters; target = resolvedEntity.group; - options = resolvedEntity.settings; + options = {...settings.get().device_options, ...resolvedEntity.settings}; definition = resolvedEntity.group.members.map((e) => zigbeeHerdsmanConverters.findByDevice(e.getDevice())); } diff --git a/test/publish.test.js b/test/publish.test.js index 8187bb23..a610d020 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -618,7 +618,7 @@ describe('Publish', () => { expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({state: 'ON', brightness: 100}); }); - it('Should use transition when brightness', async () => { + it('Should use transition on brightness command', async () => { const device = zigbeeHerdsman.devices.bulb_color; settings.set(['devices', device.ieeeAddr, 'transition'], 20); const endpoint = device.getEndpoint(1); @@ -629,6 +629,17 @@ describe('Publish', () => { expect(endpoint.command.mock.calls[0]).toEqual(["genLevelCtrl", "moveToLevelWithOnOff", {level: 20, transtime: 200}, {}]); }); + it('Should use transition from device_options on brightness command', async () => { + const device = zigbeeHerdsman.devices.bulb_color; + settings.set(['device_options'], {transition: 20}); + const endpoint = device.getEndpoint(1); + const payload = {brightness: 20}; + await MQTT.events.message('zigbee2mqtt/bulb_color/set', JSON.stringify(payload)); + await flushPromises(); + expect(endpoint.command).toHaveBeenCalledTimes(1); + expect(endpoint.command.mock.calls[0]).toEqual(["genLevelCtrl", "moveToLevelWithOnOff", {level: 20, transtime: 200}, {}]); + }); + it('Transition parameter should not influence brightness on state ON', async () => { // https://github.com/Koenkk/zigbee2mqtt/issues/3563 const device = zigbeeHerdsman.devices.bulb_color;