From 6b7bd9da371c76a680db704cefb90d7d7fbbb67d Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Wed, 11 Dec 2019 20:15:42 +0100 Subject: [PATCH] Re-add model to device information. #2497 --- lib/controller.js | 6 +++++- test/controller.test.js | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index e780b5c4..11b02aaf 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -272,7 +272,11 @@ class Controller { 'applicationVersion', 'stackVersion', 'zclVersion', 'hardwareVersion', 'dateCode', 'softwareBuildID', ]; - messagePayload.device = {friendlyName: entity.name}; + messagePayload.device = { + friendlyName: entity.name, + model: entity.mapped ? entity.mapped.model : 'unknown', + }; + attributes.forEach((a) => messagePayload.device[a] = device[a]); } diff --git a/test/controller.test.js b/test/controller.test.js index 9d1be501..412f4c42 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -403,7 +403,12 @@ describe('Controller', () => { MQTT.publish.mockClear(); await controller.publishEntityState('bulb', {state: 'ON'}); await flushPromises(); - expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/bulb', '{"state":"ON","brightness":50,"color_temp":370,"linkquality":99,"device":{"friendlyName":"bulb","ieeeAddr":"0x000b57fffec6a5b2","networkAddress":40369,"type":"Router","manufacturerID":4476,"powerSource":"Mains (single phase)"}}', {"qos": 0, "retain": true}, expect.any(Function)); + expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/bulb', '{"state":"ON","brightness":50,"color_temp":370,"linkquality":99,"device":{"friendlyName":"bulb","model":"LED1545G12","ieeeAddr":"0x000b57fffec6a5b2","networkAddress":40369,"type":"Router","manufacturerID":4476,"powerSource":"Mains (single phase)"}}', {"qos": 0, "retain": true}, expect.any(Function)); + + // Unsupported device should have model "unknown" + await controller.publishEntityState('unsupported2', {state: 'ON'}); + await flushPromises(); + expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/unsupported2', '{"state":"ON","device":{"friendlyName":"unsupported2","model":"unknown","ieeeAddr":"0x0017880104e45529","networkAddress":6536,"type":"EndDevice","manufacturerID":0,"powerSource":"Battery"}}', {"qos": 0, "retain": false}, expect.any(Function)); }); it('Publish entity state no empty messages', async () => {