Skip to content

Commit

Permalink
add tests for receive.ts and homeassistant.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
slugzero committed Jan 13, 2024
1 parent 8373a62 commit 0b40473
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/homeassistant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});
});
7 changes: 7 additions & 0 deletions test/receive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
2 changes: 2 additions & 0 deletions test/stub/zigbeeHerdsman.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 0b40473

Please sign in to comment.