From 3e071a73dfef4a923852f9fdb7dbc45d40164576 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 2 Aug 2020 10:08:55 +0200 Subject: [PATCH] Invert cover tests. https://github.com/Koenkk/zigbee-herdsman-converters/issues/1447 --- test/publish.test.js | 19 +++++++++++++++++++ test/receive.test.js | 18 ++++++++++++++++++ test/stub/data.js | 5 ++++- test/stub/zigbeeHerdsman.js | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/test/publish.test.js b/test/publish.test.js index fa9abf34..c192de33 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -524,6 +524,25 @@ describe('Publish', () => { expectNothingPublished(); }); + it('Should allow to invert cover', async () => { + const device = zigbeeHerdsman.devices.J1; + const endpoint = device.getEndpoint(1); + + // Non-inverted (open = 100, close = 0) + await MQTT.events.message('zigbee2mqtt/J1_cover/set', JSON.stringify({position: 90})); + await flushPromises(); + expect(endpoint.command).toHaveBeenCalledTimes(1); + expect(endpoint.command).toHaveBeenCalledWith("closuresWindowCovering", "goToLiftPercentage", {percentageliftvalue: 10}, {}); + + // // Inverted + endpoint.command.mockClear(); + settings.set(['devices', device.ieeeAddr, 'invert_cover'], true); + await MQTT.events.message('zigbee2mqtt/J1_cover/set', JSON.stringify({position: 90})); + await flushPromises(); + expect(endpoint.command).toHaveBeenCalledTimes(1); + expect(endpoint.command).toHaveBeenCalledWith("closuresWindowCovering", "goToLiftPercentage", {percentageliftvalue: 90}, {}); + }); + it('Should send state update on toggle specific endpoint', async () => { const device = zigbeeHerdsman.devices.QBKG03LM; const endpoint = device.getEndpoint(2); diff --git a/test/receive.test.js b/test/receive.test.js index e002f29b..561e1c6e 100755 --- a/test/receive.test.js +++ b/test/receive.test.js @@ -67,6 +67,24 @@ describe('Receive', () => { expect(MQTT.publish.mock.calls[0][2]).toStrictEqual({"qos": 1, "retain": false}); }); + it('Should allow to invert cover', async () => { + const device = zigbeeHerdsman.devices.J1; + + // Non-inverted (open = 100, close = 0) + await zigbeeHerdsman.events.message({data: {currentPositionLiftPercentage: 90, currentPositionTiltPercentage: 80}, cluster: 'closuresWindowCovering', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10}); + await flushPromises(); + expect(MQTT.publish).toHaveBeenCalledTimes(1); + expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/J1_cover', JSON.stringify({position: 10, tilt: 20, linkquality: 10}), {retain: false, qos: 0}, expect.any(Function)); + + // Inverted + MQTT.publish.mockClear(); + settings.set(['devices', device.ieeeAddr, 'invert_cover'], true); + await zigbeeHerdsman.events.message({data: {currentPositionLiftPercentage: 90, currentPositionTiltPercentage: 80}, cluster: 'closuresWindowCovering', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10}); + await flushPromises(); + expect(MQTT.publish).toHaveBeenCalledTimes(1); + expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/J1_cover', JSON.stringify({position: 90, tilt: 80, linkquality: 10}), {retain: false, qos: 0}, expect.any(Function)); + }); + it('Should allow to disable the legacy integration', async () => { const device = zigbeeHerdsman.devices.WXKG11LM; settings.set(['devices', device.ieeeAddr, 'legacy'], false); diff --git a/test/stub/data.js b/test/stub/data.js index f7177beb..cd463527 100644 --- a/test/stub/data.js +++ b/test/stub/data.js @@ -154,7 +154,10 @@ function writeDefaultConfiguration() { }, '0x0017880104e44559': { friendly_name: '3157100_thermostat', - } + }, + '0x0017880104a44559': { + friendly_name: 'J1_cover', + }, }, groups: { '1': { diff --git a/test/stub/zigbeeHerdsman.js b/test/stub/zigbeeHerdsman.js index 6fb38728..c27cb87d 100644 --- a/test/stub/zigbeeHerdsman.js +++ b/test/stub/zigbeeHerdsman.js @@ -149,6 +149,7 @@ const devices = { 'GL-S-007ZS': new Device('Router', '0x0017880104e45526', 6540,4151, [new Endpoint(1, [0], [], '0x0017880104e45526')], true, "Mains (single phase)", 'GL-S-007ZS'), 'U202DST600ZB': new Device('Router', '0x0017880104e43559', 6540,4151, [new Endpoint(10, [0, 6], [], '0x0017880104e43559'), new Endpoint(11, [0, 6], [], '0x0017880104e43559')], true, "Mains (single phase)", 'U202DST600ZB'), '3157100': new Device('Router', '0x0017880104e44559', 6542,4151, [new Endpoint(1, [], [], '0x0017880104e44559')], true, "Mains (single phase)", '3157100'), + 'J1': new Device('Router', '0x0017880104a44559', 6543,4151, [new Endpoint(1, [], [], '0x0017880104a44559')], true, "Mains (single phase)", 'J1 (5502)'), } const groups = {