Skip to content

Commit

Permalink
Update networkAddress when different on deviceAnnounce. Koenkk/zigbee…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Oct 4, 2019
1 parent 21566b9 commit 9d63b7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ class Controller extends events.EventEmitter {
debug.log(`Device announce '${payload.ieeeAddr}'`);
const device = Device.byIeeeAddr(payload.ieeeAddr);
device.updateLastSeen();

if (device.networkAddress !== payload.networkAddress) {
debug.log(`Device '${payload.ieeeAddr}' announced with new networkAddress '${payload.networkAddress}'`);
device.networkAddress = payload.networkAddress;
device.save();
}

const data: Events.DeviceAnnouncePayload = {device};
this.emit(Events.Events.deviceAnnounce, data);
}
Expand Down
8 changes: 8 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ describe('Controller', () => {
expect(events.deviceAnnounce[0].device.modelID).toBe('myModelID');
});

it('Device announce event should update network address when different', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
expect(events.deviceAnnounce.length).toBe(0);
await mockAdapterEvents['deviceAnnounce']({networkAddress: 9999, ieeeAddr: '0x129'});
expect(controller.getDeviceByIeeeAddr('0x129').networkAddress).toBe(9999);
});

it('Device leave event and remove from database', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
Expand Down

0 comments on commit 9d63b7f

Please sign in to comment.