Skip to content

Commit

Permalink
Log error when there is nothing to bind. #3159
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Mar 20, 2020
1 parent 92d8eb2 commit 6cc2689
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/extension/deviceBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DeviceBind extends BaseExtension {

const sourceName = source.settings.friendlyName;
const targetName = targetKey === 'default_bind_group' ? targetKey : target.settings.friendlyName;
let attemptedToBindSomething = false;

// Find which clusters are supported by both the source and target.
// Groups are assumed to support all clusters.
Expand All @@ -43,6 +44,7 @@ class DeviceBind extends BaseExtension {

if (source.endpoint.supportsOutputCluster(cluster) && targetValid) {
logger.debug(`${type}ing cluster '${cluster}' from '${sourceName}' to '${targetName}'`);
attemptedToBindSomething = true;
try {
let bindTarget = null;
if (target.type === 'group') bindTarget = target.group;
Expand Down Expand Up @@ -75,6 +77,11 @@ class DeviceBind extends BaseExtension {
}
}
}

if (!attemptedToBindSomething) {
logger.error(`Nothing to bind from '${sourceName}' to '${targetName}'`);
this.mqtt.log(`device_${type}_failed`, {from: sourceName, to: targetName});
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/deviceBind.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ describe('Device bind', () => {
expect(JSON.parse(MQTT.publish.mock.calls[2][1])).toStrictEqual({type: 'device_bind', message: {from: 'remote', to: 'bulb_color', cluster: 'genLevelCtrl'}});
});

it('Should log error when there is nothing to bind', async () => {
const device = zigbeeHerdsman.devices.bulb_color;
const endpoint = device.getEndpoint(1);
mockClear(device);
logger.error.mockClear();
MQTT.events.message('zigbee2mqtt/bridge/bind/remote', 'button');
await flushPromises();
expect(endpoint.bind).toHaveBeenCalledTimes(0);
expect(logger.error).toHaveBeenCalledWith(`Nothing to bind from 'remote' to 'button'`);
});

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

0 comments on commit 6cc2689

Please sign in to comment.