fix: use homebrew async locking primitive to order file writing
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index dbfbe41fdfd2981bb35ab238e8d4e10c614bb035..d8f67c21460b626875d01be4bae961e93d1c3b78 100644 (file)
@@ -168,6 +168,21 @@ export class ChargingStationUtils {
       logger.error(`${logPrefix} ${errorMsg}`);
       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,
+      };
+      logger.warn(
+        `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default values`
+      );
+    }
   }
 
   public static checkConnectorsConfiguration(
@@ -374,7 +389,7 @@ export class ChargingStationUtils {
   public static stationTemplateToStationInfo(
     stationTemplate: ChargingStationTemplate
   ): ChargingStationInfo {
-    stationTemplate = Utils.cloneObject(stationTemplate);
+    stationTemplate = Utils.cloneObject<ChargingStationTemplate>(stationTemplate);
     delete stationTemplate.power;
     delete stationTemplate.powerUnit;
     delete stationTemplate?.Connectors;
@@ -456,15 +471,15 @@ export class ChargingStationUtils {
     let limit: number, matchingChargingProfile: ChargingProfile;
     // Get charging profiles for connector and sort by stack level
     const chargingProfiles =
-      Utils.cloneObject(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)?.sort(
-        (a, b) => b.stackLevel - a.stackLevel
-      ) ?? [];
+      Utils.cloneObject<ChargingProfile[]>(
+        chargingStation.getConnectorStatus(connectorId)?.chargingProfiles
+      )?.sort((a, b) => b.stackLevel - a.stackLevel) ?? [];
     // Get profiles on connector 0
     if (chargingStation.getConnectorStatus(0)?.chargingProfiles) {
       chargingProfiles.push(
-        ...Utils.cloneObject(chargingStation.getConnectorStatus(0).chargingProfiles).sort(
-          (a, b) => b.stackLevel - a.stackLevel
-        )
+        ...Utils.cloneObject<ChargingProfile[]>(
+          chargingStation.getConnectorStatus(0).chargingProfiles
+        ).sort((a, b) => b.stackLevel - a.stackLevel)
       );
     }
     if (Utils.isNotEmptyArray(chargingProfiles)) {