mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-03 10:31:37 +00:00
Touchlink factory reset #3281
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user