diff --git a/api/lib/ZwaveClient.ts b/api/lib/ZwaveClient.ts index 31655eee4fa..1ce3445ea18 100644 --- a/api/lib/ZwaveClient.ts +++ b/api/lib/ZwaveClient.ts @@ -731,6 +731,7 @@ class ZwaveClient extends TypedEventEmitter { private _inclusionState: InclusionState = undefined + private _controllerListenersAdded: boolean = false public get driverReady() { return this.driver && this._driverReady && !this.closed } @@ -4271,39 +4272,55 @@ class ZwaveClient extends TypedEventEmitter { /* ignore */ }) - this.driver.controller.removeAllListeners() - - this.driver.controller - .on('inclusion started', this._onInclusionStarted.bind(this)) - .on('exclusion started', this._onExclusionStarted.bind(this)) - .on('inclusion stopped', this._onInclusionStopped.bind(this)) - .on('exclusion stopped', this._onExclusionStopped.bind(this)) - .on('inclusion failed', this._onInclusionFailed.bind(this)) - .on('exclusion failed', this._onExclusionFailed.bind(this)) - .on('node found', this._onNodeFound.bind(this)) - .on('node added', this._onNodeAdded.bind(this)) - .on('node removed', this._onNodeRemoved.bind(this)) - .on( - 'rebuild routes progress', - this._onRebuildRoutesProgress.bind(this), - ) - .on('rebuild routes done', this._onRebuildRoutesDone.bind(this)) - .on( - 'statistics updated', - this._onControllerStatisticsUpdated.bind(this), - ) - .on( - 'firmware update progress', - this._onControllerFirmwareUpdateProgress.bind(this), - ) - .on( - 'firmware update finished', - this._onControllerFirmwareUpdateFinished.bind(this), - ) - .on( - 'status changed', - this._onControllerStatusChanged.bind(this), - ) + if (!this._controllerListenersAdded) { + this._controllerListenersAdded = true + this.driver.controller + .on( + 'inclusion started', + this._onInclusionStarted.bind(this), + ) + .on( + 'exclusion started', + this._onExclusionStarted.bind(this), + ) + .on( + 'inclusion stopped', + this._onInclusionStopped.bind(this), + ) + .on( + 'exclusion stopped', + this._onExclusionStopped.bind(this), + ) + .on('inclusion failed', this._onInclusionFailed.bind(this)) + .on('exclusion failed', this._onExclusionFailed.bind(this)) + .on('node found', this._onNodeFound.bind(this)) + .on('node added', this._onNodeAdded.bind(this)) + .on('node removed', this._onNodeRemoved.bind(this)) + .on( + 'rebuild routes progress', + this._onRebuildRoutesProgress.bind(this), + ) + .on( + 'rebuild routes done', + this._onRebuildRoutesDone.bind(this), + ) + .on( + 'statistics updated', + this._onControllerStatisticsUpdated.bind(this), + ) + .on( + 'firmware update progress', + this._onControllerFirmwareUpdateProgress.bind(this), + ) + .on( + 'firmware update finished', + this._onControllerFirmwareUpdateFinished.bind(this), + ) + .on( + 'status changed', + this._onControllerStatusChanged.bind(this), + ) + } } catch (error) { // Fixes freak error in "driver ready" handler #1309 logger.error(error.message)