From 4dff3039b8a3a3b3383cfb321bc2275b942652ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 12 Sep 2022 14:22:31 +0200 Subject: [PATCH] Fix ATG connectors status initialization MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 35 ++++++++++++++++--- src/charging-station/ChargingStation.ts | 1 + src/types/AutomaticTransactionGenerator.ts | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) 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; -- 2.34.1