From: Jérôme Benoit Date: Wed, 5 Jun 2024 12:09:24 +0000 (+0200) Subject: fix: fix clear charging profiles with no connector in payload X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ec6dd88b156eac9a14afd0d349ed58bb02fa920e;p=e-mobility-charging-stations-simulator.git fix: fix clear charging profiles with no connector in payload Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 7c64c2ad..6ec517c0 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1053,41 +1053,46 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { return OCPP16Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN } const { connectorId } = commandPayload - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - if (!chargingStation.hasConnector(connectorId!)) { - logger.error( - `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector id ${connectorId}` - ) - return OCPP16Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN - } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const connectorStatus = chargingStation.getConnectorStatus(connectorId!) - if (connectorId != null && isNotEmptyArray(connectorStatus?.chargingProfiles)) { - connectorStatus.chargingProfiles = [] - logger.debug( - `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${connectorId}` - ) - return OCPP16Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED - } - if (connectorId == null) { + if (connectorId != null) { + if (!chargingStation.hasConnector(connectorId)) { + logger.error( + `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector id ${connectorId}` + ) + return OCPP16Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN + } + const connectorStatus = chargingStation.getConnectorStatus(connectorId) + if (isNotEmptyArray(connectorStatus?.chargingProfiles)) { + connectorStatus.chargingProfiles = [] + logger.debug( + `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${connectorId}` + ) + return OCPP16Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED + } + } else { let clearedCP = false if (chargingStation.hasEvses) { for (const evseStatus of chargingStation.evses.values()) { for (const status of evseStatus.connectors.values()) { - clearedCP = OCPP16ServiceUtils.clearChargingProfiles( + const clearedConnectorCP = OCPP16ServiceUtils.clearChargingProfiles( chargingStation, commandPayload, status.chargingProfiles ) + if (clearedConnectorCP && !clearedCP) { + clearedCP = true + } } } } else { for (const id of chargingStation.connectors.keys()) { - clearedCP = OCPP16ServiceUtils.clearChargingProfiles( + const clearedConnectorCP = OCPP16ServiceUtils.clearChargingProfiles( chargingStation, commandPayload, chargingStation.getConnectorStatus(id)?.chargingProfiles ) + if (clearedConnectorCP && !clearedCP) { + clearedCP = true + } } } if (clearedCP) {