refactor: make the exponential backoff implementation for tunable
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
index aa2012dfac33eae26a49dc86b688bda0e6d26c28..d058866abae0da08c3d43937af6e3931e0872c6d 100644 (file)
@@ -2,7 +2,7 @@
 
 import { AsyncResource } from 'node:async_hooks';
 
-import { AuthorizedTagsCache, type ChargingStation, ChargingStationUtils } from './internal';
+import { type ChargingStation, ChargingStationUtils, IdTagsCache } from './internal';
 import { BaseError } from '../exception';
 // import { PerformanceStatistics } from '../performance';
 import { PerformanceStatistics } from '../performance/PerformanceStatistics';
@@ -33,7 +33,6 @@ export class AutomaticTransactionGenerator extends AsyncResource {
   public readonly configuration: AutomaticTransactionGeneratorConfiguration;
   public started: boolean;
   private readonly chargingStation: ChargingStation;
-  private idTagIndex: number;
 
   private constructor(
     automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration,
@@ -43,7 +42,6 @@ export class AutomaticTransactionGenerator extends AsyncResource {
     this.started = false;
     this.configuration = automaticTransactionGeneratorConfiguration;
     this.chargingStation = chargingStation;
-    this.idTagIndex = 0;
     this.connectorsStatus = new Map<number, Status>();
     this.initializeConnectorsStatus();
   }
@@ -323,8 +321,8 @@ export class AutomaticTransactionGenerator extends AsyncResource {
     const measureId = 'StartTransaction with ATG';
     const beginId = PerformanceStatistics.beginMeasure(measureId);
     let startResponse: StartTransactionResponse;
-    if (this.chargingStation.hasAuthorizedTags()) {
-      const idTag = AuthorizedTagsCache.getInstance().getIdTag(
+    if (this.chargingStation.hasIdTags()) {
+      const idTag = IdTagsCache.getInstance().getIdTag(
         this.configuration?.idTagDistribution,
         this.chargingStation,
         connectorId
@@ -419,7 +417,7 @@ export class AutomaticTransactionGenerator extends AsyncResource {
   private logPrefix = (connectorId?: number): string => {
     return Utils.logPrefix(
       ` ${this.chargingStation.stationInfo.chargingStationId} | ATG${
-        connectorId !== undefined ? ` on connector #${connectorId.toString()}` : ''
+        !Utils.isNullOrUndefined(connectorId) ? ` on connector #${connectorId.toString()}` : ''
       }:`
     );
   };