Touchlink factory reset #3281

This commit is contained in:
Koen Kanters
2020-06-15 19:19:57 +02:00
parent 62dc88ec87
commit 79b4dbd24f
2 changed files with 41 additions and 0 deletions
+13
View File
@@ -24,6 +24,7 @@ class Bridge extends Extension {
'config/lastseen': this.configLastSeen.bind(this),
'config/elapsed': this.configElapsed.bind(this),
'config/loglevel': this.configLogLevel.bind(this),
'touchlink/factoryreset': this.touchlinkFactoryReset.bind(this),
};
}
@@ -169,6 +170,18 @@ class Bridge extends Extension {
return utils.getResponse(message, {value}, null);
}
async touchlinkFactoryReset(message) {
logger.info('Start touchlink factory reset');
const result = await this.zigbee.touchlinkFactoryReset();
if (result) {
logger.info('Successfully factory reset device through Touchlink');
return utils.getResponse(message, {}, null);
} else {
logger.error('Failed to factory reset device through Touchlink');
throw new Error('Failed to factory reset device through Touchlink');
}
}
/**
* Utils
*/
+28
View File
@@ -548,4 +548,32 @@ describe('Bridge', () => {
{retain: false, qos: 0}, expect.any(Function)
);
});
it('Should allow to touchlink factory reset (succeeds)', async () => {
MQTT.publish.mockClear();
zigbeeHerdsman.touchlinkFactoryReset.mockClear();
zigbeeHerdsman.touchlinkFactoryReset.mockReturnValueOnce(true);
MQTT.events.message('zigbee2mqtt/bridge/request/touchlink/factoryReset', '');
await flushPromises();
expect(zigbeeHerdsman.touchlinkFactoryReset).toHaveBeenCalledTimes(1);
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/touchlink/factoryReset',
JSON.stringify({"data":{},"status":"ok"}),
{retain: false, qos: 0}, expect.any(Function)
);
});
it('Should allow to touchlink factory reset (fails)', async () => {
MQTT.publish.mockClear();
zigbeeHerdsman.touchlinkFactoryReset.mockClear();
zigbeeHerdsman.touchlinkFactoryReset.mockReturnValueOnce(false);
MQTT.events.message('zigbee2mqtt/bridge/request/touchlink/factoryReset', '');
await flushPromises();
expect(zigbeeHerdsman.touchlinkFactoryReset).toHaveBeenCalledTimes(1);
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/touchlink/factoryReset',
JSON.stringify({"data":{},"status":"error","error":"Failed to factory reset device through Touchlink"}),
{retain: false, qos: 0}, expect.any(Function)
);
});
});