From ac8a84feb2e9d46d72eb96d1c9cfc4f9a9ba4a6e Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Thu, 19 Mar 2020 23:04:39 +0100 Subject: [PATCH] Update converters. --- npm-shrinkwrap.json | 12 ++++++------ package.json | 2 +- test/entityPublish.test.js | 27 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 15516d22..96ec518c 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -5251,9 +5251,9 @@ "dev": true }, "react-is": { - "version": "16.13.0", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.0.tgz", - "integrity": "sha512-GFMtL0vHkiBv9HluwNZTggSn/sCyEt9n02aM0dSAjGGyqyNlAyftYm4phPxdvCigG15JreC5biwxCgTAJZ7yAA==", + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", "dev": true }, "readable-stream": { @@ -14811,9 +14811,9 @@ } }, "zigbee-herdsman-converters": { - "version": "12.0.52", - "resolved": "https://registry.npmjs.org/zigbee-herdsman-converters/-/zigbee-herdsman-converters-12.0.52.tgz", - "integrity": "sha512-AXPhjkodRXDWenz+3UaYQYtr50UqnCBdzR2GsnGMLkR/A183q/Vj0BHDtRlcH7MY3HwiWVP3hcJBTF9ycqwKSw==", + "version": "12.0.53", + "resolved": "https://registry.npmjs.org/zigbee-herdsman-converters/-/zigbee-herdsman-converters-12.0.53.tgz", + "integrity": "sha512-tXVGpciUDMORmdjVPnnFJFbSVqg6Qkq/G3l80/3YtL5OX1+fZ0qCqlMKFrZMpu4wg7gRmrZqPiSD/KsMR17zKw==", "requires": { "axios": "*", "tar-stream": "*" diff --git a/package.json b/package.json index cb8aa9e4..295d27dc 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "semver": "*", "winston": "*", "zigbee-herdsman": "0.12.65", - "zigbee-herdsman-converters": "12.0.52" + "zigbee-herdsman-converters": "12.0.53" }, "devDependencies": { "eslint": "*", diff --git a/test/entityPublish.test.js b/test/entityPublish.test.js index a52ef2dd..6f7429f5 100644 --- a/test/entityPublish.test.js +++ b/test/entityPublish.test.js @@ -712,7 +712,6 @@ describe('Entity publish', () => { expect(endpoint.command).toHaveBeenCalledWith("closuresWindowCovering", "stop", {}, {}); }); - it('Should turn device on with on/off when transition is provided', async () => { const device = zigbeeHerdsman.devices.bulb_color; const endpoint = device.getEndpoint(1); @@ -778,6 +777,32 @@ describe('Entity publish', () => { 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('When device is turned off with transition and turned on WITHOUT transition it should restore the 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)]); + + // Turn on again + await MQTT.events.message('zigbee2mqtt/bulb_color/set', JSON.stringify({state: 'ON'})); + await flushPromises(); + expect(endpoint.command).toHaveBeenCalledTimes(2); + expect(endpoint.command.mock.calls[1]).toEqual(["genLevelCtrl", "moveToLevelWithOnOff", {level: 200, transtime: 0}, {}]); + expect(MQTT.publish).toHaveBeenCalledTimes(2); + expect(MQTT.publish.mock.calls[1]).toEqual(["zigbee2mqtt/bulb_color", JSON.stringify({state: 'ON', brightness: 200}), {"qos": 0, "retain": false}, expect.any(Function)]); + }); + it('Home Assistant: should set state', async () => { settings.set(['homeassistant'], true); const device = zigbeeHerdsman.devices.bulb_color;