fix: properly handle undefined connector id at remote start transaction
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 5 Jun 2024 15:11:29 +0000 (17:11 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 5 Jun 2024 15:11:29 +0000 (17:11 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/types/ocpp/1.6/Requests.ts

index 6ec517c0088f4c4ffd85c41f83e44d66d7ed8ea7..fc5190469c83b91675c9d5da12eec4f80eb2f7a2 100644 (file)
@@ -420,7 +420,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         if (response.status === GenericStatus.Accepted) {
           const { connectorId, idTag } = request
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-          chargingStation.getConnectorStatus(connectorId)!.transactionRemoteStarted = true
+          chargingStation.getConnectorStatus(connectorId!)!.transactionRemoteStarted = true
           chargingStation.ocppRequestService
             .requestHandler<Partial<OCPP16StartTransactionRequest>, OCPP16StartTransactionResponse>(
             chargingStation,
@@ -1165,6 +1165,13 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     chargingStation: ChargingStation,
     commandPayload: RemoteStartTransactionRequest
   ): Promise<GenericResponse> {
+    if (commandPayload.connectorId == null) {
+      do {
+        commandPayload.connectorId = randomInt(1, chargingStation.getNumberOfConnectors())
+      } while (
+        chargingStation.getConnectorStatus(commandPayload.connectorId)?.transactionStarted === true
+      )
+    }
     const { connectorId: transactionConnectorId, idTag, chargingProfile } = commandPayload
     if (!chargingStation.hasConnector(transactionConnectorId)) {
       return this.notifyRemoteStartTransactionRejected(
index b8a184632cf4e1791d7540eb2e35a56faa35f7e6..8cfc8bc8375a52f3618e5faecbd4641f3c2b0d30 100644 (file)
@@ -61,7 +61,6 @@ export abstract class OCPPIncomingRequestService extends EventEmitter {
       `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
       error
     )
-    console.error('params set', params)
     if (params.throwError === false && params.errorResponse != null) {
       return params.errorResponse
     }
index c57be2032751277115f298947575d7877457d4cd..e186679f5004938c7662615dfa4fde8d29133300 100644 (file)
@@ -77,7 +77,7 @@ export interface ChangeConfigurationRequest extends JsonObject {
 }
 
 export interface RemoteStartTransactionRequest extends JsonObject {
-  connectorId: number
+  connectorId?: number
   idTag: string
   chargingProfile?: OCPP16ChargingProfile
 }