From 0111681cb7a7a82e1a93ef629d5ae881a02e4ede Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Fri, 31 Jan 2020 22:42:24 +0100 Subject: [PATCH] Update converters. https://github.com/Koenkk/zigbee2mqtt/issues/2850 --- npm-shrinkwrap.json | 6 +++--- package.json | 2 +- test/entityPublish.test.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index a3aab1651..1bcbea5e9 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -13445,9 +13445,9 @@ } }, "zigbee-herdsman-converters": { - "version": "12.0.13", - "resolved": "https://registry.npmjs.org/zigbee-herdsman-converters/-/zigbee-herdsman-converters-12.0.13.tgz", - "integrity": "sha512-9OTIMJ/pvlj5CjDJiHMmozsvohX7nQH2xZD8bQ4wkEBG5dzKPEoCSIglNtRzKqC6HPOiMYRg6ha+iE+nZKAoRw==", + "version": "12.0.14", + "resolved": "https://registry.npmjs.org/zigbee-herdsman-converters/-/zigbee-herdsman-converters-12.0.14.tgz", + "integrity": "sha512-auaufrzDor7fXKXqAW2gTAL1B5w03ozH0WXv9GMAdQmPDfOy+U4gX2R2YAeqN5R7n1N0GuzhdrwRDJyAOlzf2w==", "dependencies": { "@babel/code-frame": { "version": "7.5.5", diff --git a/package.json b/package.json index 882a7cca8..10dda4b54 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "semver": "*", "winston": "*", "zigbee-herdsman": "0.12.43", - "zigbee-herdsman-converters": "12.0.13" + "zigbee-herdsman-converters": "12.0.14" }, "devDependencies": { "eslint": "*", diff --git a/test/entityPublish.test.js b/test/entityPublish.test.js index c101d2d30..feab5f1fb 100644 --- a/test/entityPublish.test.js +++ b/test/entityPublish.test.js @@ -738,6 +738,38 @@ describe('Entity publish', () => { expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({state: 'OFF'}); }); + it('When device is turned off and on with transition with report enabled it should restore correct brightness', async () => { + const device = zigbeeHerdsman.devices.bulb_color; + const endpoint = device.getEndpoint(1); + // Set initial brightness in state + await MQTT.events.message('zigbee2mqtt/bulb_color/set', JSON.stringify({brightness: 200})); + await flushPromises(); + endpoint.command.mockClear(); + MQTT.publish.mockClear(); + + // Turn off + await MQTT.events.message('zigbee2mqtt/bulb_color/set', JSON.stringify({state: 'OFF', transition: 3})); + await flushPromises(); + expect(endpoint.command).toHaveBeenCalledTimes(1); + expect(endpoint.command.mock.calls[0]).toEqual(["genLevelCtrl", "moveToLevelWithOnOff", {level: 0, transtime: 30}, {}]); + expect(MQTT.publish).toHaveBeenCalledTimes(1); + expect(MQTT.publish.mock.calls[0]).toEqual(["zigbee2mqtt/bulb_color", JSON.stringify({state: 'OFF', brightness: 200}), {"qos": 0, "retain": false}, expect.any(Function)]); + + // Bulb reports brightness while decreasing brightness + await zigbeeHerdsman.events.message({data: {currentLevel: 1}, cluster: 'genLevelCtrl', device, endpoint, type: 'attributeReport', linkquality: 10}); + await flushPromises(); + expect(MQTT.publish).toHaveBeenCalledTimes(2); + expect(MQTT.publish.mock.calls[1]).toEqual(["zigbee2mqtt/bulb_color", JSON.stringify({state: 'OFF', brightness: 1, linkquality: 10}), {"qos": 0, "retain": false}, expect.any(Function)]); + + // Turn on again + await MQTT.events.message('zigbee2mqtt/bulb_color/set', JSON.stringify({state: 'ON', transition: 3})); + await flushPromises(); + expect(endpoint.command).toHaveBeenCalledTimes(2); + expect(endpoint.command.mock.calls[1]).toEqual(["genLevelCtrl", "moveToLevelWithOnOff", {level: 200, transtime: 30}, {}]); + expect(MQTT.publish).toHaveBeenCalledTimes(3); + expect(MQTT.publish.mock.calls[2]).toEqual(["zigbee2mqtt/bulb_color", JSON.stringify({state: 'ON', brightness: 200, linkquality: 10}), {"qos": 0, "retain": false}, expect.any(Function)]); + }); + it('Home Assistant: should set state', async () => { settings.set(['homeassistant'], true); const device = zigbeeHerdsman.devices.bulb_color;