From 1b066d9f598efcd2157e348ec22bc0e8f0fa4734 Mon Sep 17 00:00:00 2001 From: Oli <932481+tb-killa@users.noreply.github.com> Date: Tue, 19 Mar 2019 20:29:41 +0100 Subject: [PATCH] extend controller.js function getDeviceInfoForMqtt (#1274) * Add Discord channel. https://github.com/Koenkk/zigbee2mqtt.io/issues/31 * extend controller.js function getDeviceInfoForMqtt extend controller.js with `` zclVersion, appVersion, stackVersion, hwVersion, swBuildId, `` * Rework #2 Only Publish hwVersion and swBuildId as this seems to be valid as posible. Map with default option 'unknown' to be in a good way. * Fix tests * Update README.md --- lib/controller.js | 4 +++- test/controller.test.js | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index 71581957..5cc85a12 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -267,7 +267,7 @@ class Controller { getDeviceInfoForMqtt(ieeeAddr) { const device = this.zigbee.getDevice(ieeeAddr); - const {type, nwkAddr, manufId, manufName, powerSource, modelId, status} = device; + const {type, nwkAddr, manufId, manufName, powerSource, modelId, hwVersion, swBuildId, status} = device; const deviceSettings = settings.getDevice(device.ieeeAddr); return { @@ -279,6 +279,8 @@ class Controller { manufName, powerSource, modelId, + hwVersion: hwVersion ? hwVersion : 'unknown', + swBuildId: swBuildId ? swBuildId : 'unknown', status, }; } diff --git a/test/controller.test.js b/test/controller.test.js index 43deb713..4d9fb0ef 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -17,6 +17,8 @@ describe('Controller', () => { return { modelId: 'TRADFRI bulb E27 CWS opal 600lm', manufName: 'IKEA', + hwVersion: '1.1', + swBuildId: '2.0', }; }, }; @@ -48,14 +50,23 @@ describe('Controller', () => { }, }); + const payload = { + 'state': 'ON', + 'device': { + 'ieeeAddr': '0x12345678', + 'friendlyName': 'test', + 'manufName': 'IKEA', + 'modelId': 'TRADFRI bulb E27 CWS opal 600lm', + 'hwVersion': '1.1', + 'swBuildId': '2.0', + }, + }; + const device = {ieeeAddr: '0x12345678', modelId: 'TRADFRI bulb E27 CWS opal 600lm'}; const message = utils.zigbeeMessage(device, 'genOnOff', 'devChange', {onOff: 1}, 1); controller.onZigbeeMessage(message); expect(mqttPublish).toHaveBeenCalledTimes(1); - expect(mqttPublish.mock.calls[0][1]).toBe( - `{"state":"ON","device":{"ieeeAddr":"0x12345678","friendlyName":"test",` + - `"manufName":"IKEA","modelId":"TRADFRI bulb E27 CWS opal 600lm"}}` - ); + expect(JSON.parse(mqttPublish.mock.calls[0][1])).toStrictEqual(payload); } );