From: Julian Buecher Date: Wed, 7 Jun 2023 07:19:09 +0000 (+0200) Subject: fix: missing status updates regarding reservation cancellation and replacement X-Git-Tag: v1.2.16~2^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ec9f36cc584e72b454151d8c871d8bf0faa7b7d7;p=e-mobility-charging-stations-simulator.git fix: missing status updates regarding reservation cancellation and replacement --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 85623e28..726a2ce9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -933,7 +933,7 @@ export class ChargingStation { public async addReservation(reservation: Reservation): Promise { const [exists, reservationFound] = this.doesReservationExists(reservation); if (exists) { - await this.removeReservation(reservationFound); + await this.removeReservation(reservationFound, ReservationTerminationReason.REPLACE_EXISTING); } this.getConnectorStatus(reservation.connectorId).reservation = reservation; await OCPPServiceUtils.sendAndSetConnectorStatus( @@ -955,8 +955,11 @@ export class ChargingStation { delete connector.reservation; break; case ReservationTerminationReason.TRANSACTION_STARTED: - case ReservationTerminationReason.EXPIRED: - case ReservationTerminationReason.RESERVATION_CANCELED: + delete connector.reservation; + break; + case ReservationTerminationReason.RESERVATION_CANCELED || + ReservationTerminationReason.REPLACE_EXISTING || + ReservationTerminationReason.EXPIRED: await OCPPServiceUtils.sendAndSetConnectorStatus( this, reservation.connectorId, @@ -1010,14 +1013,20 @@ export class ChargingStation { for (const evse of this.evses.values()) { for (const connector of evse.connectors.values()) { if (connector?.reservation?.expiryDate.toString() < new Date().toISOString()) { - await this.removeReservation(connector.reservation); + await this.removeReservation( + connector.reservation, + ReservationTerminationReason.EXPIRED + ); } } } } else { for (const connector of this.connectors.values()) { if (connector?.reservation?.expiryDate.toString() < new Date().toISOString()) { - await this.removeReservation(connector.reservation); + await this.removeReservation( + connector.reservation, + ReservationTerminationReason.EXPIRED + ); } } } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 21da0052..596f684c 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1621,7 +1621,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ); return OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_REJECTED; } - await chargingStation.removeReservation(reservation); + await chargingStation.removeReservation( + reservation, + ReservationTerminationReason.RESERVATION_CANCELED + ); return OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_ACCEPTED; } catch (error) { return this.handleIncomingRequestError( diff --git a/src/types/ocpp/1.6/Reservation.ts b/src/types/ocpp/1.6/Reservation.ts index bbc3de7a..2197e171 100644 --- a/src/types/ocpp/1.6/Reservation.ts +++ b/src/types/ocpp/1.6/Reservation.ts @@ -11,6 +11,7 @@ export enum ReservationTerminationReason { TRANSACTION_STARTED = 'TransactionStarted', CONNECTOR_STATE_CHANGED = 'ConnectorStateChanged', RESERVATION_CANCELED = 'ReservationCanceled', + REPLACE_EXISTING = 'ReplaceExisting', } export enum ReservationFilterKey {