Skip to content

Commit

Permalink
Added <operation>_failed logging (#2636)
Browse files Browse the repository at this point in the history
* Added <operation>_failed logging
for external tools (like Zigbee2MqttAssistant), this will allow the tool to know when an operation is failed.
#2223

* Added _failed logging to binding operations too

* Added _failed to group operations
  • Loading branch information
carldebilly authored and Koenkk committed Jan 7, 2020
1 parent 8a72916 commit cabb1f3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/extension/bridgeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class BridgeConfig extends BaseExtension {

if (!entity) {
logger.error(`Cannot ${lookup[action][2]}, device '${message}' does not exist`);

this.mqtt.log(`device_${lookup[action][0]}_failed`, message);
return;
}

Expand Down Expand Up @@ -306,6 +308,8 @@ class BridgeConfig extends BaseExtension {
logger.error(`Failed to ${lookup[action][2]} ${entity.settings.friendlyName} (${error})`);
// eslint-disable-next-line
logger.error(`See https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html#zigbee2mqttbridgeconfigremove for more info`);

this.mqtt.log(`device_${lookup[action][0]}_failed`, message);
}

if (action === 'ban') {
Expand Down
4 changes: 4 additions & 0 deletions lib/extension/deviceBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class DeviceBind extends BaseExtension {
`Failed to ${type} cluster '${cluster}' from '${sourceName}' to ` +
`'${targetName}' (${error})`,
);
this.mqtt.log(
`device_${type}_failed`,
{from: sourceName, to: targetName, cluster},
);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/extension/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class Groups extends BaseExtension {

if (!group || group.type !== 'group') {
logger.error(`Group '${topicMatch[1]}' does not exist`);
this.mqtt.log(
`device_group_${type}_failed`,
{friendly_name: message, group: topicMatch[1], error: 'group doesn\'t exists'});
return;
}
} else if (topic.match(topicRegexRemoveAll)) {
Expand All @@ -153,6 +156,9 @@ class Groups extends BaseExtension {
const entity = this.zigbee.resolveEntity(message);
if (!entity || !entity.type === 'device') {
logger.error(`Device '${message}' does not exist`);
this.mqtt.log(
`device_group_${type}_failed`,
{friendly_name: message, group: topicMatch[1], error: 'entity doesn\'t exists'});
return;
}

Expand Down
6 changes: 4 additions & 2 deletions test/bridgeConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ describe('Bridge config', () => {
MQTT.events.message('zigbee2mqtt/bridge/config/remove', 'bulb_color');
await flushPromises();
expect(device.removeFromNetwork).toHaveBeenCalledTimes(1);
expect(MQTT.publish).toHaveBeenCalledTimes(1);
expect(settings.getDevice('bulb_color')).toStrictEqual({"ID": "0x000b57fffec6a5b3", "friendlyName": "bulb_color", "friendly_name": "bulb_color", "retain": false})
expect(MQTT.publish).toHaveBeenCalledTimes(0);
expect(MQTT.publish).toHaveBeenCalledTimes(1);
});

it('Should handle when ban fails', async () => {
Expand All @@ -381,8 +382,9 @@ describe('Bridge config', () => {
MQTT.events.message('zigbee2mqtt/bridge/config/ban', 'bulb_color');
await flushPromises();
expect(device.removeFromNetwork).toHaveBeenCalledTimes(1);
expect(MQTT.publish).toHaveBeenCalledTimes(1);
expect(settings.getDevice('bulb_color')).toStrictEqual({"ID": "0x000b57fffec6a5b3", "friendlyName": "bulb_color", "friendly_name": "bulb_color", "retain": false})
expect(MQTT.publish).toHaveBeenCalledTimes(0);
expect(MQTT.publish).toHaveBeenCalledTimes(1);
});

it('Should allow to touchlink factory reset (OK)', async () => {
Expand Down

0 comments on commit cabb1f3

Please sign in to comment.