From 0b40473c51980ccb16f6293728fa78a399968fd4 Mon Sep 17 00:00:00 2001 From: slugzero <2014249+slugzero@users.noreply.github.com> Date: Sat, 13 Jan 2024 14:31:37 +0100 Subject: [PATCH] add tests for receive.ts and homeassistant.ts --- test/homeassistant.test.js | 36 ++++++++++++++++++++++++++++++++++++ test/receive.test.js | 7 +++++++ test/stub/zigbeeHerdsman.js | 2 ++ 3 files changed, 45 insertions(+) diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index db3b746e86..ffc9dca19e 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -2491,4 +2491,40 @@ describe('HomeAssistant extension', () => { expect.any(Function), ); }); + + it('Should publish discovery message when a converter announces changed exposes', async () => { + MQTT.publish.mockClear(); + const device = zigbeeHerdsman.devices['BMCT-SLZ']; + const data = {deviceMode: 0} + const msg = {data, cluster: 'manuSpecificBosch10', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10}; + await zigbeeHerdsman.events.message(msg); + const payload = { + 'availability':[{'topic':'zigbee2mqtt/bridge/state'}], + 'command_topic':'zigbee2mqtt/0x18fc26000000cafe/set/device_mode', + 'device':{ + 'identifiers':['zigbee2mqtt_0x18fc26000000cafe'], + 'manufacturer':'Bosch', + 'model':'Light/shutter control unit II (BMCT-SLZ)', + 'name':'0x18fc26000000cafe', + 'sw_version':null, + 'via_device':'zigbee2mqtt_bridge_0x00124b00120144ae' + }, + 'entity_category':'config', + 'icon':'mdi:tune', + 'json_attributes_topic':'zigbee2mqtt/0x18fc26000000cafe', + 'name':'Device mode', + 'object_id':'0x18fc26000000cafe_device_mode', + 'options':['light','shutter','disabled'], + 'origin': origin, + 'state_topic':'zigbee2mqtt/0x18fc26000000cafe', + 'unique_id':'0x18fc26000000cafe_device_mode_zigbee2mqtt', + 'value_template':'{{ value_json.device_mode }}' + } + expect(MQTT.publish).toHaveBeenCalledWith( + "homeassistant/select/0x18fc26000000cafe/device_mode/config", + stringify(payload), + { retain: true, qos: 1 }, + expect.any(Function), + ); + }); }); diff --git a/test/receive.test.js b/test/receive.test.js index f0b0e1554b..e4078dbda9 100755 --- a/test/receive.test.js +++ b/test/receive.test.js @@ -467,4 +467,11 @@ describe('Receive', () => { expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/SP600_OLD'); expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({energy: 6.65, power: 496}); }); + it('Should emit DevicesChanged event when a converter announces changed exposes', async () => { + const device = zigbeeHerdsman.devices['BMCT-SLZ']; + const data = {deviceMode: 0} + const payload = {data, cluster: 'manuSpecificBosch10', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10}; + await zigbeeHerdsman.events.message(payload); + expect(MQTT.publish.mock.calls[0][0]).toStrictEqual("zigbee2mqtt/bridge/devices"); + }); }); diff --git a/test/stub/zigbeeHerdsman.js b/test/stub/zigbeeHerdsman.js index 1d1ef57695..e1bffa8ae6 100644 --- a/test/stub/zigbeeHerdsman.js +++ b/test/stub/zigbeeHerdsman.js @@ -204,6 +204,8 @@ const devices = { 'heating_actuator': new Device('Router', '0x0017880104e45562', 6545,4151, [new Endpoint(1, [0,3,4,513], [1026])], true, "Mains (single phase)", "heating.actuator"), 'bj_scene_switch': new Device('EndDevice', '0xd85def11a1002caa', 50117, 4398, [new Endpoint(10, [0,4096], [3,4,5,6,8,25,768,4096], '0xd85def11a1002caa', [{target: bulb_color_2.endpoints[0], cluster: {ID: 8, name: 'genLevelCtrl'}}, {target: bulb_color_2.endpoints[0], cluster: {ID: 6, name: 'genOnOff'}}, {target: bulb_color_2.endpoints[0], cluster: {ID: 768, name: 'lightingColorCtrl'}},]), new Endpoint(11, [0,4096], [3,4,5,6,8,25,768,4096], '0xd85def11a1002caa')], true, 'Battery', 'RB01', false, 'Busch-Jaeger', '20161222', '1.2.0'), 'GW003-AS-IN-TE-FC': new Device('Router', '0x0017548104a44669', 6545,4699, [new Endpoint(1, [3], [0,3,513,514], '0x0017548104a44669')], true, "Mains (single phase)", 'Adapter Zigbee FUJITSU'), + 'BMCT-SLZ': new Device('Router', '0x18fc26000000cafe', 6546,4617, [new Endpoint(1, [0,3,4,5,258,1794,2820,2821,64672], [10,25], '0x18fc26000000cafe')], true, "Mains (single phase)", 'RBSH-MMS-ZB-EU'), + } const mock = {