refactor(simulator): factor out data transfer response
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 25 May 2023 19:42:52 +0000 (21:42 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 25 May 2023 19:42:52 +0000 (21:42 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/OCPPConstants.ts

index 9e4ff3e0d9f19b839d5f17d91b92d02a43407838..f39e8cfa000136680e3d03aa1a9776a3e783ba54 100644 (file)
@@ -1488,13 +1488,9 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
   ): OCPP16DataTransferResponse {
     try {
       if (Object.values(OCPP16DataTransferVendorId).includes(commandPayload.vendorId)) {
-        return {
-          status: OCPP16DataTransferStatus.ACCEPTED,
-        };
+        return OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_ACCEPTED;
       }
-      return {
-        status: OCPP16DataTransferStatus.UNKNOWN_VENDOR_ID,
-      };
+      return OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_UNKNOWN_VENDOR_ID;
     } catch (error) {
       return this.handleIncomingRequestError(
         chargingStation,
index 5a271f5902f2a8f36e39d42cbdd407b32be97498..e82b7d70a6704110df3950baeb059e01df9ce28a 100644 (file)
@@ -97,10 +97,18 @@ export class OCPPConstants {
     status: TriggerMessageStatus.NOT_IMPLEMENTED,
   });
 
+  static readonly OCPP_DATA_TRANSFER_RESPONSE_ACCEPTED = Object.freeze({
+    status: DataTransferStatus.ACCEPTED,
+  });
+
   static readonly OCPP_DATA_TRANSFER_RESPONSE_REJECTED = Object.freeze({
     status: DataTransferStatus.REJECTED,
   });
 
+  static readonly OCPP_DATA_TRANSFER_RESPONSE_UNKNOWN_VENDOR_ID = Object.freeze({
+    status: DataTransferStatus.UNKNOWN_VENDOR_ID,
+  });
+
   protected constructor() {
     // This is intentional
   }