fix(simulator): properly handle template change at ATG initialization
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 10 Nov 2023 14:50:30 +0000 (15:50 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 10 Nov 2023 14:50:30 +0000 (15:50 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts

index 38f4901cda48f2e2722a076875ef156d482144e0..1775c8cd3bbd551faacf37733003ed03126bf4cf 100644 (file)
@@ -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 (
index 3ecf33d23f5e100c5948323c32402d0f04f5e268..e7b71b0521da42570a7b9d8d9d0c351bfbee747b 100644 (file)
@@ -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();