From e6948a57d6857b7b8667cbc8e707c0d79dafbc72 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 31 Jul 2023 00:10:29 +0200 Subject: [PATCH] refactor: cleanup reservation methods scope MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 56 ++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7eef4100..1636f547 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1008,7 +1008,27 @@ export class ChargingStation { } } - public startReservationExpirationSetInterval(customInterval?: number): void { + public isConnectorReservable( + reservationId: number, + idTag?: string, + connectorId?: number, + ): boolean { + const reservationExists = !isUndefined(this.getReservationBy('reservationId', reservationId)); + if (arguments.length === 1) { + return !reservationExists; + } else if (arguments.length > 1) { + const userReservationExists = + !isUndefined(idTag) && isUndefined(this.getReservationBy('idTag', idTag!)) ? false : true; + const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0; + const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0; + return ( + !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable + ); + } + return false; + } + + private startReservationExpirationSetInterval(customInterval?: number): void { const interval = customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_OBSERVATION_INTERVAL; if (interval > 0) { @@ -1050,29 +1070,15 @@ export class ChargingStation { } } - public restartReservationExpiryDateSetInterval(): void { - this.stopReservationExpirationSetInterval(); - this.startReservationExpirationSetInterval(); + private stopReservationExpirationSetInterval(): void { + if (this.reservationExpirationSetInterval) { + clearInterval(this.reservationExpirationSetInterval); + } } - public isConnectorReservable( - reservationId: number, - idTag?: string, - connectorId?: number, - ): boolean { - const reservationExists = !isUndefined(this.getReservationBy('reservationId', reservationId)); - if (arguments.length === 1) { - return !reservationExists; - } else if (arguments.length > 1) { - const userReservationExists = - !isUndefined(idTag) && isUndefined(this.getReservationBy('idTag', idTag!)) ? false : true; - const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0; - const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0; - return ( - !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable - ); - } - return false; + private restartReservationExpiryDateSetInterval(): void { + this.stopReservationExpirationSetInterval(); + this.startReservationExpirationSetInterval(); } private getNumberOfReservableConnectors(): number { @@ -1126,12 +1132,6 @@ export class ChargingStation { return this.stationInfo.supervisionUrlOcppConfiguration ?? false; } - private stopReservationExpirationSetInterval(): void { - if (this.reservationExpirationSetInterval) { - clearInterval(this.reservationExpirationSetInterval); - } - } - private getSupervisionUrlOcppKey(): string { return this.stationInfo.supervisionUrlOcppKey ?? VendorParametersKey.ConnectionUrl; } -- 2.34.1