From 6cc2689593074425d2dbd93e4502edf23521e611 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Fri, 20 Mar 2020 19:00:00 +0100 Subject: [PATCH] Log error when there is nothing to bind. #3159 --- lib/extension/deviceBind.js | 7 +++++++ test/deviceBind.test.js | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/extension/deviceBind.js b/lib/extension/deviceBind.js index 6cace0530..ade66b32d 100644 --- a/lib/extension/deviceBind.js +++ b/lib/extension/deviceBind.js @@ -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}); + } } } diff --git a/test/deviceBind.test.js b/test/deviceBind.test.js index c6f48ec75..047d18ab7 100644 --- a/test/deviceBind.test.js +++ b/test/deviceBind.test.js @@ -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);