Log error when there is nothing to bind. #3159

This commit is contained in:
Koen Kanters
2020-03-20 19:00:00 +01:00
parent 92d8eb2b6b
commit 6cc2689593
2 changed files with 18 additions and 0 deletions
+7
View File
@@ -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.
@@ -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;
@@ -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});
}
}
}
+11
View File
@@ -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);