From: Jérôme Benoit Date: Fri, 10 Nov 2023 14:50:30 +0000 (+0100) Subject: fix(simulator): properly handle template change at ATG initialization X-Git-Tag: v1.2.24~22 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=61854f7c58dc65fe730bab9883cf88f67b8c9d68;p=e-mobility-charging-stations-simulator.git fix(simulator): properly handle template change at ATG initialization Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 38f4901c..1775c8cd 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -356,7 +356,11 @@ export class AutomaticTransactionGenerator extends AsyncResource { delete connectorStatus?.lastRunDate; delete connectorStatus?.stopDate; delete connectorStatus?.stoppedDate; - if (!this.started && connectorStatus?.start === true) { + if ( + !this.started && + (connectorStatus?.start === true || + this.chargingStation.getAutomaticTransactionGeneratorConfiguration().enable === false) + ) { connectorStatus.start = false; } return ( diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 3ecf33d2..e7b71b05 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -697,7 +697,7 @@ export class ChargingStation extends EventEmitter { // Restart the ATG this.stopAutomaticTransactionGenerator(); delete this.automaticTransactionGeneratorConfiguration; - if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { + if (this.getAutomaticTransactionGeneratorConfiguration().enable === true) { this.startAutomaticTransactionGenerator(); } if (this.getEnableStatistics() === true) { @@ -849,17 +849,17 @@ export class ChargingStation extends EventEmitter { let automaticTransactionGeneratorConfiguration: | AutomaticTransactionGeneratorConfiguration | undefined; - const automaticTransactionGeneratorConfigurationFromFile = - this.getConfigurationFromFile()?.automaticTransactionGenerator; + const stationTemplate = this.getTemplateFromFile(); + const stationConfiguration = this.getConfigurationFromFile(); if ( this.getAutomaticTransactionGeneratorPersistentConfiguration() && - automaticTransactionGeneratorConfigurationFromFile + stationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash && + stationConfiguration?.automaticTransactionGenerator ) { automaticTransactionGeneratorConfiguration = - automaticTransactionGeneratorConfigurationFromFile; + stationConfiguration?.automaticTransactionGenerator; } else { - automaticTransactionGeneratorConfiguration = - this.getTemplateFromFile()?.AutomaticTransactionGenerator; + automaticTransactionGeneratorConfiguration = stationTemplate?.AutomaticTransactionGenerator; } this.automaticTransactionGeneratorConfiguration = { ...Constants.DEFAULT_ATG_CONFIGURATION, @@ -1253,13 +1253,13 @@ export class ChargingStation extends EventEmitter { dirname(this.templateFile.replace('station-templates', 'configurations')), `${getHashId(this.index, stationTemplate)}.json`, ); - const chargingStationConfiguration = this.getConfigurationFromFile(); + const stationConfiguration = this.getConfigurationFromFile(); if ( - chargingStationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash && + stationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash && // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - (chargingStationConfiguration?.connectorsStatus || chargingStationConfiguration?.evsesStatus) + (stationConfiguration?.connectorsStatus || stationConfiguration?.evsesStatus) ) { - this.initializeConnectorsOrEvsesFromFile(chargingStationConfiguration); + this.initializeConnectorsOrEvsesFromFile(stationConfiguration); } else { this.initializeConnectorsOrEvsesFromTemplate(stationTemplate); } @@ -2175,7 +2175,7 @@ export class ChargingStation extends EventEmitter { } // Start the ATG - if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { + if (this.getAutomaticTransactionGeneratorConfiguration().enable === true) { this.startAutomaticTransactionGenerator(); } this.wsConnectionRestarted === true && this.flushMessageBuffer();