refactor: remove uneeded helper in reservation code
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 30 Jul 2023 16:58:41 +0000 (18:58 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 30 Jul 2023 16:58:41 +0000 (18:58 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index c379ec7bd0ea08e1e68c8e62ac3179add092d406..7eef4100355d0113f23848f72bac8c26c9b38acc 100644 (file)
@@ -936,7 +936,7 @@ export class ChargingStation {
     );
   }
 
-  public getReservationOnConnectorId0Enabled(): boolean {
+  public getReserveConnectorZeroSupported(): boolean {
     return convertToBoolean(
       getConfigurationKey(this, StandardParametersKey.ReserveConnectorZeroSupported)!.value,
     );
@@ -1055,10 +1055,6 @@ export class ChargingStation {
     this.startReservationExpirationSetInterval();
   }
 
-  public validateIncomingRequestWithReservation(connectorId: number, idTag: string): boolean {
-    return this.getReservationBy('connectorId', connectorId)?.idTag === idTag;
-  }
-
   public isConnectorReservable(
     reservationId: number,
     idTag?: string,
index 2659458f70401bdad6fbd7d6b250ccce6888f9cb..87277e88c41e547f715acf1602351a34ed93c6da 100644 (file)
@@ -833,8 +833,11 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       chargingStation.getConnectorStatus(0)!.status === OCPP16ChargePointStatus.Reserved;
     if (
       (reserved &&
-        !chargingStation.validateIncomingRequestWithReservation(transactionConnectorId, idTag)) ||
-      (reservedOnConnectorZero && !chargingStation.validateIncomingRequestWithReservation(0, idTag))
+        !(
+          chargingStation.getReservationBy('connectorId', transactionConnectorId)?.idTag === idTag
+        )) ||
+      (reservedOnConnectorZero &&
+        !(chargingStation.getReservationBy('connectorId', 0)?.idTag === idTag))
     ) {
       return OCPP16Constants.OCPP_RESPONSE_REJECTED;
     }
@@ -1549,7 +1552,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
       if (!chargingStation.isConnectorAvailable(connectorId) && connectorId > 0) {
         return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED;
       }
-      if (connectorId === 0 && !chargingStation.getReservationOnConnectorId0Enabled()) {
+      if (connectorId === 0 && !chargingStation.getReserveConnectorZeroSupported()) {
         return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED;
       }
       if (!(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, connectorId, idTag))) {