From 626d3ce5e6dfdc848cb2bb5833044fe6fbe68324 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 6 Jun 2024 18:50:14 +0200 Subject: [PATCH] fix: ensure charging profiles not related to the current transaction are removed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Helpers.ts | 15 +++++++----- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 24 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 9d67e930..804eb7a1 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -416,12 +416,15 @@ export const resetConnectorStatus = (connectorStatus: ConnectorStatus | undefine if (connectorStatus == null) { return } - connectorStatus.chargingProfiles = - connectorStatus.transactionId != null && isNotEmptyArray(connectorStatus.chargingProfiles) - ? connectorStatus.chargingProfiles.filter( - chargingProfile => chargingProfile.transactionId !== connectorStatus.transactionId - ) - : [] + if (isNotEmptyArray(connectorStatus.chargingProfiles)) { + connectorStatus.chargingProfiles = connectorStatus.chargingProfiles.filter( + chargingProfile => + (chargingProfile.transactionId != null && + connectorStatus.transactionId != null && + chargingProfile.transactionId !== connectorStatus.transactionId) || + chargingProfile.transactionId == null + ) + } resetAuthorizeConnectorStatus(connectorStatus) connectorStatus.transactionRemoteStarted = false connectorStatus.transactionStarted = false diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 6e12e0a5..8852649f 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1668,21 +1668,21 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ) return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED } + if (connectorId > 0 && !chargingStation.isConnectorAvailable(connectorId)) { + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + if (connectorId === 0 && !chargingStation.getReserveConnectorZeroSupported()) { + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + if (!(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, connectorId, idTag))) { + return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED + } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const connectorStatus = chargingStation.getConnectorStatus(connectorId)! + resetAuthorizeConnectorStatus(connectorStatus) let response: OCPP16ReserveNowResponse try { - if (connectorId > 0 && !chargingStation.isConnectorAvailable(connectorId)) { - return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED - } - if (connectorId === 0 && !chargingStation.getReserveConnectorZeroSupported()) { - return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED - } - if (!(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, connectorId, idTag))) { - return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED - } await removeExpiredReservations(chargingStation) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const connectorStatus = chargingStation.getConnectorStatus(connectorId)! - resetAuthorizeConnectorStatus(connectorStatus) switch (connectorStatus.status) { case OCPP16ChargePointStatus.Faulted: response = OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED -- 2.34.1