fix: missing status updates regarding reservation cancellation and replacement
authorJulian Buecher <julian.buecher@gmx.de>
Wed, 7 Jun 2023 07:19:09 +0000 (09:19 +0200)
committerJulian Buecher <julian.buecher@gmx.de>
Wed, 7 Jun 2023 07:19:34 +0000 (09:19 +0200)
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/types/ocpp/1.6/Reservation.ts

index 85623e28596bf36796e0acefda364e7800c93c3f..726a2ce9fc63ee06253dc379d003930f9a791888 100644 (file)
@@ -933,7 +933,7 @@ export class ChargingStation {
   public async addReservation(reservation: Reservation): Promise<void> {
     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
+            );
           }
         }
       }
index 21da005239070a634ba3cb9b253c4eb1b8a769cf..596f684c3098870e1f3f8792bf586ecbcd49aa67 100644 (file)
@@ -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(
index bbc3de7a93b8b03cb993c1720e322a749993f521..2197e171deb9c49b18d5d45bea25ee28a4e36676 100644 (file)
@@ -11,6 +11,7 @@ export enum ReservationTerminationReason {
   TRANSACTION_STARTED = 'TransactionStarted',
   CONNECTOR_STATE_CHANGED = 'ConnectorStateChanged',
   RESERVATION_CANCELED = 'ReservationCanceled',
+  REPLACE_EXISTING = 'ReplaceExisting',
 }
 
 export enum ReservationFilterKey {