Skip to content

Commit

Permalink
Subscribe to nested topics for bind. Koenkk#2250
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Nov 1, 2019
1 parent 857fc23 commit 8a5f39f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/extension/deviceBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const clusters = ['genScenes', 'genOnOff', 'genLevelCtrl', 'lightingColorCtrl'];

class DeviceBind extends BaseExtension {
onMQTTConnected() {
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/bind/+`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/bind/+/+`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/unbind/+`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/unbind/+/+`);
for (let step = 1; step < 20; step++) {
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/bind${'/+'.repeat(step)}`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/unbind${'/+'.repeat(step)}`);
}
}

async onMQTTMessage(topic, message) {
Expand Down
7 changes: 7 additions & 0 deletions test/deviceBind.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe('Device bind', () => {
MQTT.publish.mockClear();
});

it('Should subscribe to nested topics', async () => {
expect(MQTT.subscribe).toHaveBeenCalledWith('zigbee2mqtt/bridge/bind/+');
expect(MQTT.subscribe).toHaveBeenCalledWith('zigbee2mqtt/bridge/bind/+/+');
expect(MQTT.subscribe).toHaveBeenCalledWith('zigbee2mqtt/bridge/bind/+/+/+');
expect(MQTT.subscribe).toHaveBeenCalledWith('zigbee2mqtt/bridge/bind/+/+/+/+/+');
});

it('Should bind', async () => {
const device = zigbeeHerdsman.devices.remote;
const target = zigbeeHerdsman.devices.bulb_color.getEndpoint(1);
Expand Down

0 comments on commit 8a5f39f

Please sign in to comment.