Add charging station instance id
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
index 877339c2da8069e1a9fa5db799bffb0b864d1642..dddfc045c9a80aba7e56ab3e985727188bbd6f87 100644 (file)
@@ -11,8 +11,8 @@ import logger from '../utils/Logger';
 
 export default class AutomaticTransactionGenerator {
   public started: boolean;
-  private chargingStation: ChargingStation;
-  private connectorsStatus: Map<number, Status>;
+  private readonly chargingStation: ChargingStation;
+  private readonly connectorsStatus: Map<number, Status>;
 
   constructor(chargingStation: ChargingStation) {
     this.chargingStation = chargingStation;
@@ -40,6 +40,9 @@ export default class AutomaticTransactionGenerator {
   }
 
   private startConnectors(): void {
+    if (this.connectorsStatus?.size > 0 && this.connectorsStatus.size !== this.chargingStation.getNumberOfConnectors()) {
+      this.connectorsStatus.clear();
+    }
     for (const connectorId of this.chargingStation.connectors.keys()) {
       if (connectorId > 0) {
         this.startConnector(connectorId);
@@ -63,8 +66,8 @@ export default class AutomaticTransactionGenerator {
         this.stopConnector(connectorId);
         break;
       }
-      if (!this.chargingStation.isRegistered()) {
-        logger.error(this.logPrefix(connectorId) + ' entered in transaction loop while the charging station is not registered');
+      if (!this.chargingStation.isInAcceptedState()) {
+        logger.error(this.logPrefix(connectorId) + ' entered in transaction loop while the charging station is not in accepted state');
         this.stopConnector(connectorId);
         break;
       }