From a3d26ceeb2b38c388d166b55775e7fa805ac10ae Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Wed, 1 May 2019 21:50:01 +0200 Subject: [PATCH] Update zigbee-shepherd-converters to 9.0.0. --- lib/extension/deviceAvailability.js | 14 +++--- lib/extension/devicePublish.js | 78 +++++++++++++++-------------- npm-shrinkwrap.json | 12 ++--- package.json | 2 +- test/devicePublish.test.js | 8 +-- 5 files changed, 61 insertions(+), 53 deletions(-) diff --git a/lib/extension/deviceAvailability.js b/lib/extension/deviceAvailability.js index 591eecf89..7f9d0fd1e 100644 --- a/lib/extension/deviceAvailability.js +++ b/lib/extension/deviceAvailability.js @@ -120,12 +120,14 @@ class DeviceAvailability { }); converters.forEach((converter) => { - const converted = converter.convert(null, null, null, 'get'); - if (converted) { - this.zigbee.publish( - ieeeAddr, 'device', converted.cid, converted.cmd, converted.cmdType, - converted.zclData, converted.cfg, null, () => {} - ); + const convertedResults = converter.convert(null, null, null, 'get'); + if (convertedResults && convertedResults.length) { + convertedResults.forEach((converted) => { + this.zigbee.publish( + ieeeAddr, 'device', converted.cid, converted.cmd, converted.cmdType, + converted.zclData, converted.cfg, null, () => {} + ); + }); } }); } diff --git a/lib/extension/devicePublish.js b/lib/extension/devicePublish.js index 96e3dad68..46b6186b5 100644 --- a/lib/extension/devicePublish.js +++ b/lib/extension/devicePublish.js @@ -168,49 +168,53 @@ class DevicePublish { } // Converter didn't return a result, skip - const converted = converter.convert(key, json[key], json, topic.type, topic.postfix); - if (!converted) { + const convertedResults = converter.convert(key, json[key], json, topic.type, topic.postfix); + if (!convertedResults || !convertedResults.length) { return; } - this.zigbee.publish( - entity.ID, - entity.type, - converted.cid, - converted.cmd, - converted.cmdType, - converted.zclData, - converted.cfg, - endpoint, - (error, rsp) => { - if (!error) { - this.handlePublished(entity, topic, converter, converted, key, json[key]); - } else { - this.handlePublishError(entity, message, error); + convertedResults.forEach((converted) => { + this.zigbee.publish( + entity.ID, + entity.type, + converted.cid, + converted.cmd, + converted.cmdType, + converted.zclData, + converted.cfg, + endpoint, + (error, rsp) => { + if (!error) { + this.handlePublished(entity, topic, converter, converted, key, json[key]); + } else { + this.handlePublishError(entity, message, error); + } } + ); + + // It's possible for devices to get out of sync when writing an attribute that's not reportable. + // So here we re-read the value after a specified timeout, this timeout could for example be the + // transition time of a color change or for forcing a state read for devices that don't + // automatically report a new state when set. + // When reporting is requested for a device (report: true in device-specific settings) we won't + // ever issue a read here, as we assume the device will properly report changes. + // Only do this when the retrieve_state option is enabled for this device. + const deviceSettings = settings.getDevice(entity.ID); + if (topic.type === 'set' && entity.type === 'device' && + converted.hasOwnProperty('readAfterWriteTime') && deviceSettings && deviceSettings.retrieve_state) { + const getConvertedResults = converter.convert(key, json[key], json, 'get'); + getConvertedResults.forEach((getConverted) => { + setTimeout(() => { + this.zigbee.publish( + entity.ID, entity.type, getConverted.cid, getConverted.cmd, getConverted.cmdType, + getConverted.zclData, getConverted.cfg, endpoint, () => {} + ); + }, converted.readAfterWriteTime); + }); } - ); - // It's possible for devices to get out of sync when writing an attribute that's not reportable. - // So here we re-read the value after a specified timeout, this timeout could for example be the - // transition time of a color change or for forcing a state read for devices that don't - // automatically report a new state when set. - // When reporting is requested for a device (report: true in device-specific settings) we won't - // ever issue a read here, as we assume the device will properly report changes. - // Only do this when the retrieve_state option is enabled for this device. - const deviceSettings = settings.getDevice(entity.ID); - if (topic.type === 'set' && entity.type === 'device' && converted.hasOwnProperty('readAfterWriteTime') && - deviceSettings && deviceSettings.retrieve_state) { - const getConverted = converter.convert(key, json[key], json, 'get'); - setTimeout(() => { - this.zigbee.publish( - entity.ID, entity.type, getConverted.cid, getConverted.cmd, getConverted.cmdType, - getConverted.zclData, getConverted.cfg, endpoint, () => {} - ); - }, converted.readAfterWriteTime); - } - - usedConverters.push(converter); + usedConverters.push(converter); + }); }); return true; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 25d3ce318..6e4fba33c 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -6601,9 +6601,9 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, "uglify-js": { - "version": "3.5.9", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.9.tgz", - "integrity": "sha512-WpT0RqsDtAWPNJK955DEnb6xjymR8Fn0OlK4TT4pS0ASYsVPqr5ELhgwOwLCP5J5vHeJ4xmMmz3DEgdqC10JeQ==", + "version": "3.5.10", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.10.tgz", + "integrity": "sha512-/GTF0nosyPLbdJBd+AwYiZ+Hu5z8KXWnO0WCGt1BQ/u9Iamhejykqmz5o1OHJ53+VAk6xVxychonnApDjuqGsw==", "dev": true, "optional": true, "requires": { @@ -7071,9 +7071,9 @@ } }, "zigbee-shepherd-converters": { - "version": "8.1.5", - "resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-8.1.5.tgz", - "integrity": "sha512-jx3/foSlnMuMAQvzNA+L3ZF/1b/NnNXnCyhentdVfLm5bQDOA+by50xHKw8az2JU70NwJvKvXk0swXzpy9nJqA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-9.0.0.tgz", + "integrity": "sha512-eeAAfpkrLAUj1cGyKaRPKS44cK7mcQDRyBbMEiW4B4jdkJZUzNfsRMe1553/E6l/uGJcHbLFBf3wT8Ts8zCbiw==", "requires": { "chai": "*", "debounce": "*", diff --git a/package.json b/package.json index a966eb98e..73e82e040 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "zcl-id": "git+https://github.com/Koenkk/zcl-id.git#4fa75c92424cd070a3bf6e1f4640b1e3ad8f802d", "ziee": "*", "zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#566cba295119cb334a7a7d939b4741e59415ed80", - "zigbee-shepherd-converters": "8.1.5", + "zigbee-shepherd-converters": "9.0.0", "deep-diff": "*", "zive": "*" }, diff --git a/test/devicePublish.test.js b/test/devicePublish.test.js index b75c04ce5..e9106e15f 100644 --- a/test/devicePublish.test.js +++ b/test/devicePublish.test.js @@ -926,11 +926,13 @@ describe('DevicePublish', () => { expect(zigbee.publish.mock.calls[1][2]).toBe('lightingColorCtrl'); expect(zigbee.publish.mock.calls[1][3]).toBe('moveToColor'); await wait(10); - expect(zigbee.publish).toHaveBeenCalledTimes(4); - expect(zigbee.publish.mock.calls[2][2]).toBe('genLevelCtrl'); + expect(zigbee.publish).toHaveBeenCalledTimes(5); + expect(zigbee.publish.mock.calls[2][2]).toBe('genOnOff'); expect(zigbee.publish.mock.calls[2][3]).toBe('read'); - expect(zigbee.publish.mock.calls[3][2]).toBe('lightingColorCtrl'); + expect(zigbee.publish.mock.calls[3][2]).toBe('genLevelCtrl'); expect(zigbee.publish.mock.calls[3][3]).toBe('read'); + expect(zigbee.publish.mock.calls[4][2]).toBe('lightingColorCtrl'); + expect(zigbee.publish.mock.calls[4][3]).toBe('read'); expect(publishEntityState).toHaveBeenCalledTimes(2); expect(publishEntityState).toHaveBeenNthCalledWith(1, '0x00000020',