From: Jérôme Benoit Date: Mon, 12 Sep 2022 12:22:31 +0000 (+0200) Subject: Fix ATG connectors status initialization X-Git-Tag: v1.1.73~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4dff3039b8a3a3b3383cfb321bc2275b942652ed;p=e-mobility-charging-stations-simulator.git Fix ATG connectors status initialization Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 03297e4a..ba5b3e65 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -38,15 +38,14 @@ export default class AutomaticTransactionGenerator { this.started = false; this.configuration = automaticTransactionGeneratorConfiguration; this.chargingStation = chargingStation; - this.connectorsStatus = new Map(); - this.stopConnectors(); + this.connectorsStatus = new Map(this.buildInitialConnectorsStatus()); } public static getInstance( automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration, chargingStation: ChargingStation ): AutomaticTransactionGenerator { - if (!AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId)) { + if (AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId) === false) { AutomaticTransactionGenerator.instances.set( chargingStation.stationInfo.hashId, new AutomaticTransactionGenerator( @@ -132,6 +131,7 @@ export default class AutomaticTransactionGenerator { private async internalStartConnector(connectorId: number): Promise { this.initializeConnectorStatus(connectorId); + this.connectorsStatus.get(connectorId).start = true; logger.info( this.logPrefix(connectorId) + ' started on connector and will run for ' + @@ -281,7 +281,34 @@ export default class AutomaticTransactionGenerator { 1000 - previousRunDuration ); - this.connectorsStatus.get(connectorId).start = true; + this.connectorsStatus.get(connectorId).start = + this?.connectorsStatus.get(connectorId)?.start ?? false; + } + + private buildInitialConnectorsStatus(): [number, Status][] { + const connectorsStatus: [number, Status][] = []; + for (const connectorId of this.chargingStation.connectors.keys()) { + if (connectorId > 0) { + connectorsStatus.push([ + connectorId, + { + start: false, + authorizeRequests: 0, + acceptedAuthorizeRequests: 0, + rejectedAuthorizeRequests: 0, + startTransactionRequests: 0, + acceptedStartTransactionRequests: 0, + rejectedStartTransactionRequests: 0, + stopTransactionRequests: 0, + acceptedStopTransactionRequests: 0, + rejectedStopTransactionRequests: 0, + skippedConsecutiveTransactions: 0, + skippedTransactions: 0, + }, + ]); + } + } + return connectorsStatus; } private async startTransaction( diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 767ea76d..a6694066 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -737,6 +737,7 @@ export default class ChargingStation { if (!Utils.isEmptyArray(connectorIds)) { for (const connectorId of connectorIds) { this.automaticTransactionGenerator?.stopConnector(connectorId); + // FIXME: check if the number of connectors match the CS number of connectors } } else { this.automaticTransactionGenerator?.stop(); diff --git a/src/types/AutomaticTransactionGenerator.ts b/src/types/AutomaticTransactionGenerator.ts index de26ce62..f88659bf 100644 --- a/src/types/AutomaticTransactionGenerator.ts +++ b/src/types/AutomaticTransactionGenerator.ts @@ -11,7 +11,7 @@ export type AutomaticTransactionGeneratorConfiguration = { }; export type Status = { - start?: boolean; + start: boolean; startDate?: Date; lastRunDate?: Date; stopDate?: Date;