Code cleanups
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
index bb8d75b3ecaacbc06095c73e8216f395915b231e..0562a8973bb8bd36a60f6353e6503339e6111a63 100644 (file)
@@ -9,7 +9,7 @@ import logger from '../utils/Logger';
 export default class AutomaticTransactionGenerator {
   public timeToStop: boolean;
   private chargingStation: ChargingStation;
-  private performanceObserver: PerformanceObserver;
+  private performanceObserver!: PerformanceObserver;
 
   constructor(chargingStation: ChargingStation) {
     this.chargingStation = chargingStation;
@@ -17,7 +17,7 @@ export default class AutomaticTransactionGenerator {
     if (this.chargingStation.getEnableStatistics()) {
       this.performanceObserver = new PerformanceObserver((list) => {
         const entry = list.getEntries()[0];
-        this.chargingStation.statistics.logPerformance(entry, Constants.ENTITY_AUTOMATIC_TRANSACTION_GENERATOR);
+        this.chargingStation.performanceStatistics.logPerformance(entry, Constants.ENTITY_AUTOMATIC_TRANSACTION_GENERATOR);
         this.performanceObserver.disconnect();
       });
     }
@@ -53,7 +53,7 @@ export default class AutomaticTransactionGenerator {
     this.timeToStop = true;
   }
 
-  public async startConnector(connectorId: number): Promise<void> {
+  private async startConnector(connectorId: number): Promise<void> {
     do {
       if (this.timeToStop) {
         logger.error(this.logPrefix(connectorId) + ' Entered in transaction loop while a request to stop it was made');
@@ -96,7 +96,7 @@ export default class AutomaticTransactionGenerator {
           startResponse = await this.startTransaction(connectorId, this);
         }
         if (startResponse?.idTagInfo?.status !== AuthorizationStatus.ACCEPTED) {
-          logger.info(this.logPrefix(connectorId) + ' transaction rejected');
+          logger.warn(this.logPrefix(connectorId) + ' transaction rejected');
           await Utils.sleep(Constants.CHARGING_STATION_ATG_WAIT_TIME);
         } else {
           // Wait until end of transaction
@@ -149,13 +149,14 @@ export default class AutomaticTransactionGenerator {
   // eslint-disable-next-line consistent-this
   private async stopTransaction(connectorId: number, self: AutomaticTransactionGenerator): Promise<StopTransactionResponse> {
     const transactionId = self.chargingStation.getConnector(connectorId).transactionId;
-    return await self.chargingStation.ocppRequestService.sendStopTransaction(transactionId, self.chargingStation.getTransactionMeterStop(transactionId), self.chargingStation.getTransactionIdTag(transactionId));
+    return await self.chargingStation.ocppRequestService.sendStopTransaction(transactionId, self.chargingStation.getTransactionMeterStop(transactionId),
+      self.chargingStation.getTransactionIdTag(transactionId));
   }
 
-  private logPrefix(connectorId: number = null): string {
+  private logPrefix(connectorId?: number): string {
     if (connectorId) {
-      return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG on connector #' + connectorId.toString() + ':');
+      return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG on connector #' + connectorId.toString() + ':');
     }
-    return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG:');
+    return Utils.logPrefix(' ' + this.chargingStation.stationInfo.chargingStationId + ' ATG:');
   }
 }