Skip to content

Commit

Permalink
feat: Support coordinator check (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk authored Aug 13, 2023
1 parent a7fbf64 commit cb679f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ class Controller extends events.EventEmitter {
}
}

public async coordinatorCheck(): Promise<{missingRouters: Device[]}> {
if (await this.adapter.supportsBackup()) {
const backup = await this.adapter.backup();
const devicesInBackup = backup.devices.map((d) => `0x${d.ieeeAddress.toString('hex')}`);
const missingRouters = this.getDevices()
.filter((d) => d.type === 'Router' && !devicesInBackup.includes(d.ieeeAddr));
return {missingRouters};
} else {
throw new Error("Coordinator does not coordinator check because it doesn't support backups");
}
}

public async reset(type: 'soft' | 'hard'): Promise<void> {
await this.adapter.reset(type);
}
Expand Down
14 changes: 14 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4907,6 +4907,20 @@ describe('Controller', () => {
expect(deepClone(events.message[0])).toStrictEqual(expected);
});

it('Shouldnt throw error on coordinatorCheck when adapter doesnt support backups', async () => {
mockAdapterSupportsBackup.mockReturnValue(false);
await controller.start();
await expect(controller.coordinatorCheck()).rejects.toHaveProperty('message', `Coordinator does not coordinator check because it doesn't support backups`);
});

it('Should do a coordinator check', async () => {
mockAdapterSupportsBackup.mockReturnValue(true);
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
const result = await controller.coordinatorCheck();
expect(result.missingRouters.length).toBe(1);
expect(result.missingRouters[0].ieeeAddr).toBe('0x129');
});
});


0 comments on commit cb679f3

Please sign in to comment.