]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(ocpp20): move TransactionEvent(Started) to event listener pattern
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 16 Mar 2026 16:28:14 +0000 (17:28 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 16 Mar 2026 16:28:14 +0000 (17:28 +0100)
Move sendTransactionEvent(Started) and startTxUpdatedInterval from
inside handleRequestStartTransaction to a post-response event
listener in the constructor, matching the OCPP 1.6
RemoteStartTransaction pattern where the handler validates and
returns Accepted, then an event triggers the actual StartTransaction
message send.

src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts

index 018a03e14de478346fbc3434a52390249ff7b535..e6ce847ffce6d1ea7c38e9686654bc1e1af23e6f 100644 (file)
@@ -340,6 +340,36 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
         }
       }
     )
+    // E02.FR.01: Send TransactionEvent(Started) after accepting remote start
+    this.on(
+      OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION,
+      (
+        chargingStation: ChargingStation,
+        request: OCPP20RequestStartTransactionRequest,
+        response: OCPP20RequestStartTransactionResponse
+      ) => {
+        if (response.status === RequestStartStopStatusEnumType.Accepted) {
+          const connectorId = chargingStation.getConnectorIdByTransactionId(response.transactionId)
+          if (connectorId != null) {
+            OCPP20ServiceUtils.sendTransactionEvent(
+              chargingStation,
+              OCPP20TransactionEventEnumType.Started,
+              OCPP20TriggerReasonEnumType.RemoteStart,
+              connectorId,
+              // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+              response.transactionId!
+            ).catch((error: unknown) => {
+              logger.error(
+                `${chargingStation.logPrefix()} ${moduleName}.constructor: TransactionEvent(Started) error:`,
+                error
+              )
+            })
+            const txUpdatedInterval = this.getTxUpdatedInterval(chargingStation)
+            chargingStation.startTxUpdatedInterval(connectorId, txUpdatedInterval)
+          }
+        }
+      }
+    )
     this.on(
       OCPP20IncomingRequestCommand.TRIGGER_MESSAGE,
       (
@@ -2461,18 +2491,6 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
         evseId
       )
 
-      // E02.FR.01: Send TransactionEvent(Started) to CSMS
-      await OCPP20ServiceUtils.sendTransactionEvent(
-        chargingStation,
-        OCPP20TransactionEventEnumType.Started,
-        OCPP20TriggerReasonEnumType.RemoteStart,
-        connectorId,
-        transactionId
-      )
-
-      const txUpdatedInterval = this.getTxUpdatedInterval(chargingStation)
-      chargingStation.startTxUpdatedInterval(connectorId, txUpdatedInterval)
-
       if (chargingProfile != null) {
         connectorStatus.chargingProfiles ??= []
         connectorStatus.chargingProfiles.push(chargingProfile)