docs: add FIXME
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index e76b3a6e0bb357eca59cb59f689f4c7b191bc87c..033fc4b36f79647746106169fe462834d241e463 100644 (file)
@@ -1,4 +1,5 @@
 import crypto from 'node:crypto';
+import type EventEmitter from 'node:events';
 import path from 'node:path';
 import { fileURLToPath } from 'node:url';
 
@@ -18,6 +19,7 @@ import {
   type ChargingSchedulePeriod,
   type ChargingStationInfo,
   type ChargingStationTemplate,
+  ChargingStationWorkerMessageEvents,
   ConnectorPhaseRotation,
   type ConnectorStatus,
   ConnectorStatusEnum,
@@ -145,7 +147,7 @@ export class ChargingStationUtils {
     return connectorBootStatus;
   }
 
-  public static checkTemplateFile(
+  public static checkTemplate(
     stationTemplate: ChargingStationTemplate,
     logPrefix: string,
     templateFile: string
@@ -161,18 +163,18 @@ export class ChargingStationUtils {
       throw new BaseError(errorMsg);
     }
     if (Utils.isEmptyObject(stationTemplate.AutomaticTransactionGenerator)) {
-      stationTemplate.AutomaticTransactionGenerator = {
-        enable: false,
-        minDuration: 60,
-        maxDuration: 120,
-        minDelayBetweenTwoTransactions: 15,
-        maxDelayBetweenTwoTransactions: 30,
-        probabilityOfStart: 1,
-        stopAfterHours: 0.3,
-        stopOnConnectionFailure: true,
-      };
+      stationTemplate.AutomaticTransactionGenerator = Constants.DEFAULT_ATG_CONFIGURATION;
       logger.warn(
-        `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default values`
+        `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default: %j`,
+        Constants.DEFAULT_ATG_CONFIGURATION
+      );
+    }
+    if (
+      Utils.isNullOrUndefined(stationTemplate.idTagsFile) ||
+      Utils.isEmptyString(stationTemplate.idTagsFile)
+    ) {
+      logger.warn(
+        `${logPrefix} Missing id tags file in template file ${templateFile}. That can lead to issues with the Automatic Transaction Generator`
       );
     }
   }
@@ -539,6 +541,25 @@ export class ChargingStationUtils {
     );
   }
 
+  public static waitForChargingStationEvents = async (
+    emitter: EventEmitter,
+    event: ChargingStationWorkerMessageEvents,
+    eventsToWait: number
+  ): Promise<number> => {
+    return new Promise((resolve) => {
+      let events = 0;
+      if (eventsToWait === 0) {
+        resolve(events);
+      }
+      emitter.on(event, () => {
+        ++events;
+        if (events === eventsToWait) {
+          resolve(events);
+        }
+      });
+    });
+  };
+
   private static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
     let configuredMaxConnectors: number;
     if (Utils.isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {