Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support coordinator check #18599

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/extension/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class Bridge extends Extension {
'install_code/add': this.installCodeAdd,
'touchlink/scan': this.touchlinkScan,
'health_check': this.healthCheck,
'coordinator_check': this.coordinatorCheck,
'options': this.bridgeOptions,
// Below are deprecated
'config/last_seen': this.configLastSeen,
Expand Down Expand Up @@ -181,6 +182,14 @@ export default class Bridge extends Extension {
return utils.getResponse(message, {healthy: true}, null);
}

@bind async coordinatorCheck(message: string | KeyValue): Promise<MQTTResponse> {
const result = await this.zigbee.coordinatorCheck();
const missingRouters = result.missingRouters.map((d) => {
return {ieee_address: d.ieeeAddr, friendly_name: d.name};
});
return utils.getResponse(message, {missing_routers: missingRouters}, null);
}

@bind async groupAdd(message: string | KeyValue): Promise<MQTTResponse> {
if (typeof message === 'object' && !message.hasOwnProperty('friendly_name')) {
throw new Error(`Invalid payload`);
Expand Down
5 changes: 5 additions & 0 deletions lib/zigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ export default class Zigbee {
return this.herdsman.backup();
}

async coordinatorCheck(): Promise<{missingRouters: Device[]}> {
const check = await this.herdsman.coordinatorCheck();
return {missingRouters: check.missingRouters.map((d) => this.resolveDevice(d.ieeeAddr))};
}

async getNetworkParameters(): Promise<zh.NetworkParameters> {
return this.herdsman.getNetworkParameters();
}
Expand Down
12 changes: 12 additions & 0 deletions test/bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,18 @@ describe('Bridge', () => {
);
});

it('Should allow a coordinator check', async () => {
MQTT.publish.mockClear();
zigbeeHerdsman.coordinatorCheck.mockReturnValueOnce({missingRouters: [zigbeeHerdsman.getDeviceByIeeeAddr('0x000b57fffec6a5b2')]})
MQTT.events.message('zigbee2mqtt/bridge/request/coordinator_check', '');
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/coordinator_check',
stringify({"data":{"missing_routers":[{"friendly_name":"bulb","ieee_address":"0x000b57fffec6a5b2"}]},"status":"ok"}),
{retain: false, qos: 0}, expect.any(Function)
);
});

it('Should allow to remove device by string', async () => {
const device = zigbeeHerdsman.devices.bulb;
settings.set(['groups'], {'1': {friendly_name: 'group_1', retain: false, devices: ['0x999b57fffec6a5b9/1', '0x000b57fffec6a5b2/1', 'bulb', 'bulb/right', 'other_bulb', 'bulb_1', '0x000b57fffec6a5b2', 'bulb/room/2']}});
Expand Down
2 changes: 1 addition & 1 deletion test/frontend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('Frontend', () => {

});

it('onlythis Websocket interaction', async () => {
it('Websocket interaction', async () => {
controller = new Controller(jest.fn(), jest.fn());
await controller.start();

Expand Down
1 change: 1 addition & 0 deletions test/stub/zigbeeHerdsman.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const mock = {
touchlinkIdentify: jest.fn(),
start: jest.fn(),
backup: jest.fn(),
coordinatorCheck: jest.fn(),
isStopping: jest.fn(),
permitJoin: jest.fn(),
addInstallCode: jest.fn(),
Expand Down
Loading