fix: reset authorize fields connector status after reservation
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 6 Jun 2024 14:36:50 +0000 (16:36 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 6 Jun 2024 14:36:50 +0000 (16:36 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/Helpers.ts
src/charging-station/index.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index 15ba379bf50ff28fc28fcb3ae3ab7c93eadd5b81..9d67e9306c924cb7274aee36133ecb26f4c3c513 100644 (file)
@@ -405,6 +405,13 @@ export const initializeConnectorsMapStatus = (
   }
 }
 
+export const resetAuthorizeConnectorStatus = (connectorStatus: ConnectorStatus): void => {
+  connectorStatus.idTagLocalAuthorized = false
+  connectorStatus.idTagAuthorized = false
+  delete connectorStatus.localAuthorizeIdTag
+  delete connectorStatus.authorizeIdTag
+}
+
 export const resetConnectorStatus = (connectorStatus: ConnectorStatus | undefined): void => {
   if (connectorStatus == null) {
     return
@@ -415,14 +422,11 @@ export const resetConnectorStatus = (connectorStatus: ConnectorStatus | undefine
         chargingProfile => chargingProfile.transactionId !== connectorStatus.transactionId
       )
       : []
-  connectorStatus.idTagLocalAuthorized = false
-  connectorStatus.idTagAuthorized = false
+  resetAuthorizeConnectorStatus(connectorStatus)
   connectorStatus.transactionRemoteStarted = false
   connectorStatus.transactionStarted = false
   delete connectorStatus.transactionStart
   delete connectorStatus.transactionId
-  delete connectorStatus.localAuthorizeIdTag
-  delete connectorStatus.authorizeIdTag
   delete connectorStatus.transactionIdTag
   connectorStatus.transactionEnergyActiveImportRegisterValue = 0
   delete connectorStatus.transactionBeginMeterValue
index 8d8a83c3586549c074e4e4b1feeff5cf905d6b98..1a5f955f52011ae05e8979f81ba9e3614d42964f 100644 (file)
@@ -14,5 +14,6 @@ export {
   hasReservationExpired,
   prepareChargingProfileKind,
   removeExpiredReservations,
+  resetAuthorizeConnectorStatus,
   resetConnectorStatus
 } from './Helpers.js'
index 96fb41abc117c0a20b6f4d0c1c243cb8827cb164..6e12e0a51ae0a08283696b5a4a41c991573996c5 100644 (file)
@@ -26,6 +26,7 @@ import {
   getConnectorChargingProfiles,
   prepareChargingProfileKind,
   removeExpiredReservations,
+  resetAuthorizeConnectorStatus,
   setConfigurationKeyValue
 } from '../../../charging-station/index.js'
 import { OCPPError } from '../../../exception/index.js'
@@ -1661,6 +1662,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     commandPayload.expiryDate = convertToDate(commandPayload.expiryDate)!
     const { reservationId, idTag, connectorId } = commandPayload
+    if (!chargingStation.hasConnector(connectorId)) {
+      logger.error(
+        `${chargingStation.logPrefix()} Trying to reserve a non existing connector id ${connectorId}`
+      )
+      return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED
+    }
     let response: OCPP16ReserveNowResponse
     try {
       if (connectorId > 0 && !chargingStation.isConnectorAvailable(connectorId)) {
@@ -1673,7 +1680,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         return OCPP16Constants.OCPP_RESERVATION_RESPONSE_REJECTED
       }
       await removeExpiredReservations(chargingStation)
-      switch (chargingStation.getConnectorStatus(connectorId)?.status) {
+      // 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
           break