fix: ensure reservation expiration internal is > 0
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Jul 2023 14:34:07 +0000 (16:34 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Jul 2023 14:34:07 +0000 (16:34 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 474565ba432b9bc795745f4ced0e50e7c2fd3d39..d0c7b0780119e528ab5c6a019563f7177dc4c7ff 100644 (file)
@@ -1037,12 +1037,23 @@ export class ChargingStation {
       `${this.logPrefix()} Reservation expiration date interval is set to ${interval}
         and starts on charging station now`,
     );
-    // eslint-disable-next-line @typescript-eslint/no-misused-promises
-    this.reservationExpirationSetInterval = setInterval(async (): Promise<void> => {
-      const now = new Date();
-      if (this.hasEvses) {
-        for (const evseStatus of this.evses.values()) {
-          for (const connectorStatus of evseStatus.connectors.values()) {
+    if (interval > 0) {
+      // eslint-disable-next-line @typescript-eslint/no-misused-promises
+      this.reservationExpirationSetInterval = setInterval(async (): Promise<void> => {
+        const now = new Date();
+        if (this.hasEvses) {
+          for (const evseStatus of this.evses.values()) {
+            for (const connectorStatus of evseStatus.connectors.values()) {
+              if (connectorStatus.reservation!.expiryDate < now) {
+                await this.removeReservation(
+                  connectorStatus.reservation!,
+                  ReservationTerminationReason.EXPIRED,
+                );
+              }
+            }
+          }
+        } else {
+          for (const connectorStatus of this.connectors.values()) {
             if (connectorStatus.reservation!.expiryDate < now) {
               await this.removeReservation(
                 connectorStatus.reservation!,
@@ -1051,17 +1062,8 @@ export class ChargingStation {
             }
           }
         }
-      } else {
-        for (const connectorStatus of this.connectors.values()) {
-          if (connectorStatus.reservation!.expiryDate < now) {
-            await this.removeReservation(
-              connectorStatus.reservation!,
-              ReservationTerminationReason.EXPIRED,
-            );
-          }
-        }
-      }
-    }, interval);
+      }, interval);
+    }
   }
 
   public restartReservationExpiryDateSetInterval(): void {