From: Jérôme Benoit Date: Mon, 17 Jul 2023 14:34:07 +0000 (+0200) Subject: fix: ensure reservation expiration internal is > 0 X-Git-Tag: v1.2.18~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=42371a2ed3ad187c91417fa759fd260ae86dee7c;p=e-mobility-charging-stations-simulator.git fix: ensure reservation expiration internal is > 0 Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 474565ba..d0c7b078 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 => { - 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 => { + 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 {