diff --git a/lib/zigbee.js b/lib/zigbee.js index 6f3eeb490..0777761cd 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -60,10 +60,11 @@ class Zigbee extends events.EventEmitter { herdsmanSettings.network.panID = newPanID; } + let startResult; try { herdsmanSettings.acceptJoiningDeviceHandler = this.acceptJoiningDeviceHandler; this.herdsman = new ZigbeeHerdsman.Controller(herdsmanSettings, logger); - await this.herdsman.start(); + startResult = await this.herdsman.start(); } catch (error) { logger.error(`Error while starting zigbee-herdsman`); throw error; @@ -79,10 +80,16 @@ class Zigbee extends events.EventEmitter { this.herdsman.on('message', (data) => this.emit('event', 'message', data)); this.herdsman.on('permitJoinChanged', (data) => this.emit('permitJoinChanged', data)); - logger.info('zigbee-herdsman started'); + logger.info(`zigbee-herdsman started (${startResult})`); logger.info(`Coordinator firmware version: '${stringify(await this.getCoordinatorVersion())}'`); logger.debug(`Zigbee network parameters: ${stringify(await this.herdsman.getNetworkParameters())}`); + // Disable some legacy options on new network creation + if (startResult === 'reset') { + settings.set(['advanced', 'legacy_api'], false); + settings.set(['device_options', 'legacy'], false); + } + for (const device of this.getClients()) { // If a passlist is used, all other device will be removed from the network. const passlist = settings.get().passlist.concat(settings.get().whitelist); diff --git a/test/controller.test.js b/test/controller.test.js index d256b17dc..ee771cfe2 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -623,4 +623,11 @@ describe('Controller', () => { expect(MQTT.publish).toHaveBeenCalledTimes(1); expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/fo', 'bar', { retain: false, qos: 0 }, expect.any(Function)); }); + + it('Should disable legacy options on new network start', async () => { + expect(settings.get().advanced.legacy_api).toBeTruthy(); + zigbeeHerdsman.start.mockReturnValueOnce('reset'); + await controller.start(); + expect(settings.get().advanced.legacy_api).toBeFalsy(); + }); });