diff --git a/lib/extension/bridgeConfig.js b/lib/extension/bridgeConfig.js index b4e5ca52a6..e8c8b47aaf 100644 --- a/lib/extension/bridgeConfig.js +++ b/lib/extension/bridgeConfig.js @@ -130,10 +130,12 @@ class BridgeConfig extends BaseExtension { } async devices(topic, message) { + const coordinator = await this.zigbee.getCoordinatorVersion(); const devices = this.zigbee.getDevices().map((device) => { const payload = { ieeeAddr: device.ieeeAddr, type: device.type, + networkAddress: device.networkAddress, }; if (device.type !== 'Coordinator') { @@ -141,7 +143,6 @@ class BridgeConfig extends BaseExtension { const friendlyDevice = settings.getDevice(device.ieeeAddr); payload.model = mappedDevice ? mappedDevice.model : device.modelID; payload.friendly_name = friendlyDevice ? friendlyDevice.friendly_name : device.ieeeAddr; - payload.networkAddress = device.networkAddress; payload.manufacturerID = device.manufacturerID; payload.manufacturerName = device.manufacturerName; payload.powerSource = device.powerSource; @@ -150,6 +151,11 @@ class BridgeConfig extends BaseExtension { payload.softwareBuildID = device.softwareBuildID; payload.dateCode = device.dateCode; payload.lastSeen = device.lastSeen; + } else { + payload.friendly_name = 'Coordinator'; + payload.softwareBuildID = coordinator.type; + payload.dateCode = coordinator.meta.revision.toString(); + payload.lastSeen = Date.now(); } return payload; diff --git a/test/bridgeConfig.test.js b/test/bridgeConfig.test.js index 06a26eea83..e623b333c1 100644 --- a/test/bridgeConfig.test.js +++ b/test/bridgeConfig.test.js @@ -152,14 +152,17 @@ describe('Bridge config', () => { }); it('Should allow to get devices', async () => { + const now = Date.now; + Date.now = () => 100; MQTT.publish.mockClear(); MQTT.events.message('zigbee2mqtt/bridge/config/devices/get', ''); await flushPromises(); expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/bridge/config/devices'); const payload = JSON.parse(MQTT.publish.mock.calls[0][1]); expect(payload.length).toStrictEqual(Object.values(zigbeeHerdsman.devices).length); - expect(payload[0]).toStrictEqual({"ieeeAddr": "0x00124b00120144ae", "type": "Coordinator"}); + expect(payload[0]).toStrictEqual({"ieeeAddr": "0x00124b00120144ae", "type": "Coordinator", "dateCode": "20190425", "friendly_name": "Coordinator", networkAddress: 0, softwareBuildID: "z-Stack", lastSeen: 100}); expect(payload[1]).toStrictEqual({"friendly_name": "bulb", "ieeeAddr": "0x000b57fffec6a5b2", "lastSeen": 1000, "manufacturerID": 4476, "model": "LED1545G12", "modelID": "TRADFRI bulb E27 WS opal 980lm", "networkAddress": 40369, "powerSource": "Mains (single phase)", "type": "Router"}); + Date.now = now; }); it('Should allow to get groups', async () => { diff --git a/test/stub/zigbeeHerdsman.js b/test/stub/zigbeeHerdsman.js index 883ecf1901..6e69f05d02 100644 --- a/test/stub/zigbeeHerdsman.js +++ b/test/stub/zigbeeHerdsman.js @@ -129,7 +129,7 @@ const groups = { const mock = { start: jest.fn(), permitJoin: jest.fn(), - getCoordinatorVersion: jest.fn().mockReturnValue({type: 'z-Stack', meta: {version: 1}}), + getCoordinatorVersion: jest.fn().mockReturnValue({type: 'z-Stack', meta: {version: 1, revision: 20190425}}), getNetworkParameters: jest.fn().mockReturnValue({panID: 0x162a, extendedPanID: [0, 11, 22], channel: 15}), on: (type, handler) => { events[type] = handler;