Skip to content

Commit

Permalink
fix: Proper extended PAN ID in getNetworkParameters (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored Dec 13, 2024
1 parent 388a0c3 commit febca96
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/adapter/deconz/adapter/deconzAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,10 @@ class DeconzAdapter extends Adapter {
const panid = await this.driver.readParameterRequest(PARAM.PARAM.Network.PAN_ID);
const expanid = await this.driver.readParameterRequest(PARAM.PARAM.Network.APS_EXT_PAN_ID);
const channel = await this.driver.readParameterRequest(PARAM.PARAM.Network.CHANNEL);

return {
panID: panid as number,
extendedPanID: expanid as number,
extendedPanID: expanid as string, // read as `0x...`
channel: channel as number,
};
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/ember/adapter/emberAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ export class EmberAdapter extends Adapter {

return {
panID,
extendedPanID: parseInt(Buffer.from(extendedPanID).toString('hex'), 16),
extendedPanID: ZSpec.Utils.eui64LEBufferToHex(Buffer.from(extendedPanID)),
channel,
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/ezsp/adapter/ezspAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class EZSPAdapter extends Adapter {
public async getNetworkParameters(): Promise<NetworkParameters> {
return {
panID: this.driver.networkParams.panId,
extendedPanID: this.driver.networkParams.extendedPanId[0],
extendedPanID: ZSpec.Utils.eui64LEBufferToHex(this.driver.networkParams.extendedPanId),
channel: this.driver.networkParams.radioChannel,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/tstype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ export interface Backup {

export interface NetworkParameters {
panID: number;
extendedPanID: number;
extendedPanID: string; // `0x${string}` same as IEEE address
channel: number;
}
6 changes: 3 additions & 3 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,9 @@ class ZStackAdapter extends Adapter {
public async getNetworkParameters(): Promise<NetworkParameters> {
const result = await this.znp.requestWithReply(Subsystem.ZDO, 'extNwkInfo', {});
return {
panID: result.payload.panid,
extendedPanID: result.payload.extendedpanid,
channel: result.payload.channel,
panID: result.payload.panid as number,
extendedPanID: result.payload.extendedpanid as string, // read as IEEEADDR, so `0x${string}`
channel: result.payload.channel as number,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/adapter/zboss/adapter/zbossAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class ZBOSSAdapter extends Adapter {

return {
panID,
extendedPanID: parseInt(Buffer.from(extendedPanID).toString('hex'), 16),
extendedPanID: ZSpec.Utils.eui64LEBufferToHex(Buffer.from(extendedPanID)),
channel,
};
});
Expand Down
6 changes: 3 additions & 3 deletions src/adapter/zigate/adapter/zigateAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ class ZiGateAdapter extends Adapter {
const result = await this.driver.sendCommand(ZiGateCommandCode.GetNetworkState, {}, 10000);

return {
panID: <number>result.payload.PANID,
extendedPanID: <number>result.payload.ExtPANID,
channel: <number>result.payload.Channel,
panID: result.payload.PANID as number,
extendedPanID: result.payload.ExtPANID as string, // read as IEEEADDR, so `0x${string}`
channel: result.payload.Channel as number,
};
} catch (error) {
throw new Error(`Get network parameters failed ${error}`);
Expand Down
4 changes: 2 additions & 2 deletions test/adapter/ember/emberAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ describe('Ember Adapter Layer', () => {
it('Adapter impl: getNetworkParameters from cache', async () => {
await expect(adapter.getNetworkParameters()).resolves.toStrictEqual({
panID: DEFAULT_NETWORK_OPTIONS.panID,
extendedPanID: parseInt(Buffer.from(DEFAULT_NETWORK_OPTIONS.extendedPanID!).toString('hex'), 16),
extendedPanID: ZSpec.Utils.eui64LEBufferToHex(Buffer.from(DEFAULT_NETWORK_OPTIONS.extendedPanID!)),
channel: DEFAULT_NETWORK_OPTIONS.channelList[0],
} as TsType.NetworkParameters);
expect(mockEzspGetNetworkParameters).toHaveBeenCalledTimes(0);
Expand All @@ -2249,7 +2249,7 @@ describe('Ember Adapter Layer', () => {

await expect(adapter.getNetworkParameters()).resolves.toStrictEqual({
panID: DEFAULT_NETWORK_OPTIONS.panID,
extendedPanID: parseInt(Buffer.from(DEFAULT_NETWORK_OPTIONS.extendedPanID!).toString('hex'), 16),
extendedPanID: ZSpec.Utils.eui64LEBufferToHex(Buffer.from(DEFAULT_NETWORK_OPTIONS.extendedPanID!)),
channel: DEFAULT_NETWORK_OPTIONS.channelList[0],
} as TsType.NetworkParameters);
expect(mockEzspGetNetworkParameters).toHaveBeenCalledTimes(1);
Expand Down
11 changes: 6 additions & 5 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const mockAdapterReset = jest.fn();
const mockAdapterStop = jest.fn();
const mockAdapterStart = jest.fn().mockReturnValue('resumed');
const mockAdapterGetCoordinatorIEEE = jest.fn().mockReturnValue('0x0000012300000000');
const mockAdapterGetNetworkParameters = jest.fn().mockReturnValue({panID: 1, extendedPanID: 3, channel: 15});
const mockAdapterGetNetworkParameters = jest.fn().mockReturnValue({panID: 1, extendedPanID: '0x64c5fd698daf0c00', channel: 15});
const mocksendZclFrameToGroup = jest.fn();
const mocksendZclFrameToAll = jest.fn();
const mockAddInstallCode = jest.fn();
Expand Down Expand Up @@ -1588,7 +1588,7 @@ describe('Controller', () => {

it('Change channel on start', async () => {
mockAdapterStart.mockReturnValueOnce('resumed');
mockAdapterGetNetworkParameters.mockReturnValueOnce({panID: 1, extendedPanID: 3, channel: 25});
mockAdapterGetNetworkParameters.mockReturnValueOnce({panID: 1, extendedPanID: '0x64c5fd698daf0c00', channel: 25});
// @ts-expect-error private
const changeChannelSpy = jest.spyOn(controller, 'changeChannel');
await controller.start();
Expand All @@ -1601,7 +1601,7 @@ describe('Controller', () => {
zdoPayload,
true,
);
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: 3});
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: '0x64c5fd698daf0c00'});
expect(changeChannelSpy).toHaveBeenCalledTimes(1);
});

Expand All @@ -1621,8 +1621,9 @@ describe('Controller', () => {

it('Get network parameters', async () => {
await controller.start();
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: 3});
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: 3});
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: '0x64c5fd698daf0c00'});
// cached
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: '0x64c5fd698daf0c00'});
expect(mockAdapterGetNetworkParameters).toHaveBeenCalledTimes(1);
});

Expand Down

0 comments on commit febca96

Please sign in to comment.