Implement new api healthcheck. #3281

This commit is contained in:
Koen Kanters 2020-07-21 21:14:39 +02:00
parent 2e0b23f97c
commit db748a1333
2 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,7 @@ class Bridge extends Extension {
'config/elapsed': this.configElapsed.bind(this),
'config/log_level': this.configLogLevel.bind(this),
'touchlink/factory_reset': this.touchlinkFactoryReset.bind(this),
'health_check': this.healthCheck.bind(this),
};
}
@ -111,6 +112,10 @@ class Bridge extends Extension {
return this.removeEntity('group', message);
}
async healthCheck(message) {
return utils.getResponse(message, {healthy: true}, null);
}
async groupAdd(message) {
if (typeof message === 'object' && !message.hasOwnProperty('friendly_name')) {
throw new Error(`Invalid payload`);

View File

@ -220,6 +220,17 @@ describe('Bridge', () => {
await flushPromises();
});
it('Should allow a healthcheck', async () => {
MQTT.publish.mockClear();
MQTT.events.message('zigbee2mqtt/bridge/request/health_check', '');
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/health_check',
JSON.stringify({"data":{"healthy": true},"status":"ok"}),
{retain: false, qos: 0}, expect.any(Function)
);
});
it('Should allow to remove device by string', async () => {
const device = zigbeeHerdsman.devices.bulb;
controller.state.state = {'0x000b57fffec6a5b3': {brightness: 100}};