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
This commit is contained in:
Oli 2019-03-19 20:29:41 +01:00 committed by Koen Kanters
parent 5c9b31b2fc
commit 1b066d9f59
2 changed files with 18 additions and 5 deletions

View File

@ -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,
};
}

View File

@ -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);
}
);