From b88c8cf69b3f8143726767f8028220371bd0cf4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 27 Jan 2024 15:26:45 +0100 Subject: [PATCH] refactor: cleanup charging station events handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 44957e1e..31b8cf79 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -180,7 +180,6 @@ export class ChargingStation extends EventEmitter { private evsesConfigurationHash!: string private automaticTransactionGeneratorConfiguration?: AutomaticTransactionGeneratorConfiguration private ocppIncomingRequestService!: OCPPIncomingRequestService - private acceptedEventListenerRegistered: boolean private readonly messageBuffer: Set private configuredSupervisionUrl!: URL private autoReconnectRetryCount: number @@ -196,7 +195,6 @@ export class ChargingStation extends EventEmitter { this.started = false this.starting = false this.stopping = false - this.acceptedEventListenerRegistered = false this.wsConnection = null this.autoReconnectRetryCount = 0 this.index = index @@ -218,6 +216,11 @@ export class ChargingStation extends EventEmitter { this.on(ChargingStationEvents.updated, () => { parentPort?.postMessage(buildUpdatedMessage(this)) }) + this.on(ChargingStationEvents.accepted, () => { + this.startMessageSequence().catch(error => { + logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error) + }) + }) this.initialize() } @@ -1740,16 +1743,6 @@ export class ChargingStation extends EventEmitter { return ocppConfiguration } - private registerAcceptedEventListener (): void { - this.once(ChargingStationEvents.accepted, () => { - this.startMessageSequence().catch(error => { - logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error) - }) - this.acceptedEventListenerRegistered = false - }) - this.acceptedEventListenerRegistered = true - } - private async onOpen (): Promise { if (this.isWebSocketConnectionOpened()) { logger.info( @@ -1788,9 +1781,6 @@ export class ChargingStation extends EventEmitter { this.stationInfo?.registrationMaxRetries === -1) ) } - if (!this.acceptedEventListenerRegistered) { - this.registerAcceptedEventListener() - } if (this.isRegistered()) { this.emit(ChargingStationEvents.registered) if (this.inAcceptedState()) { -- 2.34.1