From: Jérôme Benoit Date: Sat, 13 Jan 2024 17:41:32 +0000 (+0100) Subject: fix: warn about reserved transaction started not found X-Git-Tag: v1.2.32~19 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a095d7d7fc3f3e99d472b4c57f355414c5bcb852;p=e-mobility-charging-stations-simulator.git fix: warn about reserved transaction started not found Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 571fc200..b8fce37c 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -615,33 +615,40 @@ export class OCPP16ResponseService extends OCPPResponseService { requestPayload.meterStart ) if (requestPayload.reservationId != null) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const reservation = chargingStation.getReservationBy( 'reservationId', requestPayload.reservationId - )! - if (reservation.idTag !== requestPayload.idTag) { - logger.warn( - `${chargingStation.logPrefix()} Reserved transaction ${ - payload.transactionId - } started with a different idTag ${requestPayload.idTag} than the reservation one ${ - reservation.idTag - }` + ) + if (reservation != null) { + if (reservation.idTag !== requestPayload.idTag) { + logger.warn( + `${chargingStation.logPrefix()} Reserved transaction ${ + payload.transactionId + } started with a different idTag ${requestPayload.idTag} than the reservation one ${ + reservation.idTag + }` + ) + } + if (hasReservationExpired(reservation)) { + logger.warn( + `${chargingStation.logPrefix()} Reserved transaction ${ + payload.transactionId + } started with expired reservation ${ + requestPayload.reservationId + } (expiry date: ${reservation.expiryDate.toISOString()}))` + ) + } + await chargingStation.removeReservation( + reservation, + ReservationTerminationReason.TRANSACTION_STARTED ) - } - if (hasReservationExpired(reservation)) { + } else { logger.warn( `${chargingStation.logPrefix()} Reserved transaction ${ payload.transactionId - } started with expired reservation ${ - requestPayload.reservationId - } (expiry date: ${reservation.expiryDate.toISOString()}))` + } started with unknown reservation ${requestPayload.reservationId}` ) } - await chargingStation.removeReservation( - reservation, - ReservationTerminationReason.TRANSACTION_STARTED - ) } chargingStation.stationInfo?.beginEndMeterValues === true && (await chargingStation.ocppRequestService.requestHandler< diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 3dd6ff79..53548065 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -443,7 +443,6 @@ export const buildMeterValue = ( } } if (powerSampledValueTemplate != null) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion checkMeasurandPowerDivider(chargingStation, powerSampledValueTemplate.measurand) const errMsg = `MeterValues measurand ${ powerSampledValueTemplate.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER @@ -931,7 +930,6 @@ export const buildMeterValue = ( // Energy.Active.Import.Register measurand (default) energySampledValueTemplate = getSampledValueTemplate(chargingStation, connectorId) if (energySampledValueTemplate != null) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion checkMeasurandPowerDivider(chargingStation, energySampledValueTemplate.measurand) const unitDivider = energySampledValueTemplate.unit === MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1