From: Jérôme Benoit Date: Sat, 27 Jan 2024 14:26:45 +0000 (+0100) Subject: refactor: cleanup charging station events handling X-Git-Tag: v1.2.33~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b88c8cf69b3f8143726767f8028220371bd0cf4a;p=e-mobility-charging-stations-simulator.git refactor: cleanup charging station events handling Signed-off-by: Jérôme Benoit --- 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()) {