diff --git a/src/controller/controller.ts b/src/controller/controller.ts index d5869f5c88..b9654ddb3e 100644 --- a/src/controller/controller.ts +++ b/src/controller/controller.ts @@ -77,7 +77,7 @@ class Controller extends events.EventEmitter { */ public constructor(options: Options) { super(); - this.options = mixin(DefaultOptions, options); + this.options = mixin(JSON.parse(JSON.stringify(DefaultOptions)), options); // Validate options for (const channel of this.options.network.channelList) { @@ -85,6 +85,10 @@ class Controller extends events.EventEmitter { throw new Error(`'${channel}' is an invalid channel, use a channel between 11 - 26.`); } } + + if (this.options.network.networkKey.length !== 16) { + throw new Error(`Network key must be 16 digits long, got ${this.options.network.networkKey.length}.`); + } } /** diff --git a/test/controller.test.ts b/test/controller.test.ts index e758e01a65..178d1bb5a5 100755 --- a/test/controller.test.ts +++ b/test/controller.test.ts @@ -349,6 +349,14 @@ describe('Controller', () => { }).toThrowError("'10' is an invalid channel, use a channel between 11 - 26."); }); + it('Call controller constructor error on invalid channel', async () => { + const newOptions = deepClone(options); + newOptions.network.networkKey = [1,2,3]; + expect(() => { + new Controller(newOptions); + }).toThrowError('Network key must be 16 digits long, got 3.'); + }); + it('Controller start', async () => { jest.useFakeTimers(); await controller.start(); @@ -1393,7 +1401,7 @@ describe('Controller', () => { expect(controller.getDeviceByIeeeAddr('0x171').modelID).toBe('lumi.remote.b286opcn01') }); - it('onlythis Gledopto GL-C-007/GL-C-008 join (all endpoints support genBasic but only 12 responds)', async () => { + it('Gledopto GL-C-007/GL-C-008 join (all endpoints support genBasic but only 12 responds)', async () => { // - https://github.com/Koenkk/zigbee2mqtt/issues/2872 await controller.start(); await mockAdapterEvents['deviceJoined']({networkAddress: 172, ieeeAddr: '0x172'});