build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
index 3b27f247d3419f38756582f42ba9b83248049f9d..e12fba9497629207fdd1e368c4ecd50cbfb2687c 100644 (file)
@@ -218,10 +218,9 @@ export class AutomaticTransactionGenerator {
             )
           )
           logger.info(
-            `${this.logPrefix(
-              connectorId
-            )} transaction started with id ${this.chargingStation.getConnectorStatus(connectorId)
-              ?.transactionId} and will stop in ${formatDurationMilliSeconds(waitTrxEnd)}`
+            `${this.logPrefix(connectorId)} transaction started with id ${
+              this.chargingStation.getConnectorStatus(connectorId)?.transactionId
+            } and will stop in ${formatDurationMilliSeconds(waitTrxEnd)}`
           )
           await sleep(waitTrxEnd)
           await this.stopTransaction(connectorId)
@@ -232,10 +231,9 @@ export class AutomaticTransactionGenerator {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         ++this.connectorsStatus.get(connectorId)!.skippedTransactions
         logger.info(
-          `${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus.get(
-            connectorId
-          )?.skippedConsecutiveTransactions}/${this.connectorsStatus.get(connectorId)
-            ?.skippedTransactions} transaction(s)`
+          `${this.logPrefix(connectorId)} skipped consecutively ${
+            this.connectorsStatus.get(connectorId)?.skippedConsecutiveTransactions
+          }/${this.connectorsStatus.get(connectorId)?.skippedTransactions} transaction(s)`
         )
       }
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -260,30 +258,24 @@ export class AutomaticTransactionGenerator {
   }
 
   private setStartConnectorStatus (connectorId: number): void {
-    const previousRunDuration =
-      isValidTime(this.connectorsStatus.get(connectorId)?.startDate) &&
-      isValidTime(this.connectorsStatus.get(connectorId)?.lastRunDate) &&
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      this.connectorsStatus.get(connectorId)!.lastRunDate! >
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.connectorsStatus.get(connectorId)!.startDate!
-        ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.connectorsStatus.get(connectorId)!.lastRunDate!.getTime() -
-          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-          this.connectorsStatus.get(connectorId)!.startDate!.getTime()
-        : 0
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     this.connectorsStatus.get(connectorId)!.startDate = new Date()
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    this.connectorsStatus.get(connectorId)!.stopDate = new Date(
+    if (
+      this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration ===
+        false ||
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
-        hoursToMilliseconds(
-          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-          this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.stopAfterHours
-        ) -
-        previousRunDuration
-    )
+      !isValidTime(this.connectorsStatus.get(connectorId)!.stopDate)
+    ) {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.connectorsStatus.get(connectorId)!.stopDate = new Date(
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
+          hoursToMilliseconds(
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.stopAfterHours
+          )
+      )
+    }
     delete this.connectorsStatus.get(connectorId)?.stoppedDate
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions = 0
@@ -491,10 +483,9 @@ export class AutomaticTransactionGenerator {
     let stopResponse: StopTransactionResponse | undefined
     if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
       logger.info(
-        `${this.logPrefix(
-          connectorId
-        )} stop transaction with id ${this.chargingStation.getConnectorStatus(connectorId)
-          ?.transactionId}`
+        `${this.logPrefix(connectorId)} stop transaction with id ${
+          this.chargingStation.getConnectorStatus(connectorId)?.transactionId
+        }`
       )
       stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason)
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion