Skip to content

Commit

Permalink
fix: Support install code format with pipe delimiter (#1150)
Browse files Browse the repository at this point in the history
Add a new install code in the format off <address>|<key>.
This format can be found on Bosh devices.
  • Loading branch information
yoo authored Aug 16, 2024
1 parent 16d5cfe commit 3a5b075
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,14 @@ class Controller extends events.EventEmitter {

public async addInstallCode(installCode: string): Promise<void> {
const aqaraMatch = installCode.match(/^G\$M:.+\$A:(.+)\$I:(.+)$/);
const pipeMatch = installCode.match(/^(.+)\|(.+)$/);
let ieeeAddr, key;
if (aqaraMatch) {
ieeeAddr = aqaraMatch[1];
key = aqaraMatch[2];
} else if (pipeMatch) {
ieeeAddr = pipeMatch[1];
key = pipeMatch[2];
} else {
assert(
installCode.length === 95 || installCode.length === 91,
Expand Down
11 changes: 11 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,17 @@ describe('Controller', () => {
);
});

it('Add install code pipe', async () => {
await controller.start();
const code = '54EF44100006E7DF|3313A005E177A647FC7925620AB207C4BEF5';
await controller.addInstallCode(code);
expect(mockAddInstallCode).toHaveBeenCalledTimes(1);
expect(mockAddInstallCode).toHaveBeenCalledWith(
'0x54EF44100006E7DF',
Buffer.from([0x33, 0x13, 0xa0, 0x05, 0xe1, 0x77, 0xa6, 0x47, 0xfc, 0x79, 0x25, 0x62, 0x0a, 0xb2, 0x07, 0xc4, 0xbe, 0xf5]),
);
});

it('Controller permit joining', async () => {
await controller.start();
await controller.permitJoin(true);
Expand Down

0 comments on commit 3a5b075

Please sign in to comment.