Use constants for common OCPP responses.
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 19 Apr 2020 20:20:27 +0000 (22:20 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 19 Apr 2020 20:20:27 +0000 (22:20 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.js
src/index.js
src/utils/Constants.js

index f6ed30629d6fa813ee258534dc018814de88e07a..99532afa59026884efa704bb04ba1612be5a57ca 100644 (file)
@@ -499,36 +499,26 @@ class ChargingStation {
     const keyToChange = this._configuration.configurationKey.find((element) => element.key === commandPayload.key);
     if (keyToChange) {
       keyToChange.value = commandPayload.value;
-      return {
-        status: 'Accepted',
-      };
+      return Constants.OCPP_RESPONSE_ACCEPTED;
     }
-    return {
-      status: 'Rejected',
-    };
+    return Constants.OCPP_RESPONSE_REJECTED;
   }
 
   async handleRemoteStartTransaction(commandPayload) {
     const transactionConnectorID = (commandPayload.connectorId ? commandPayload.connectorId : '1');
     if (this.isAuthorizationRequested() && this._authorizeRemoteTxRequests) {
-      // check if authorized
+      // Check if authorized
       if (this._authorizedKeys.find((value) => value === commandPayload.idTag)) {
         // Authorization successful start transaction
         setTimeout(() => this.sendStartTransaction(transactionConnectorID, commandPayload.idTag), 500);
-        return {
-          status: 'Accepted',
-        };
+        return Constants.OCPP_RESPONSE_ACCEPTED;
       }
       // Start authorization checks
-      return {
-        status: 'Rejected',
-      };
+      return Constants.OCPP_RESPONSE_REJECTED;
     }
-    // no local authorization check required => start transaction
+    // No local authorization check required => start transaction
     setTimeout(() => this.sendStartTransaction(transactionConnectorID, commandPayload.idTag), 500);
-    return {
-      status: 'Accepted',
-    };
+    return Constants.OCPP_RESPONSE_ACCEPTED;
   }
 
   async sendStartTransaction(connectorID, idTag) {
@@ -648,9 +638,7 @@ class ChargingStation {
         this.sendStopTransaction(commandPayload.transactionId, connector);
       }
     }
-    return {
-      status: 'Accepted',
-    };
+    return Constants.OCPP_RESPONSE_ACCEPTED;
   }
 
   isAuthorizationRequested() {
index 71edc5a97b9e004c56083f9db8ff885b67cddfa1..3f47f1fe0b1806b8088014a59c46a05a01edcd1a 100644 (file)
@@ -13,7 +13,7 @@ class Bootstrap {
         let numStationsTotal = 0;
         Configuration.getChargingStationTemplateURLs().forEach((stationURL) => {
           try {
-            // load file
+            // Load file
             const fileDescriptor = fs.openSync(stationURL.file, 'r');
             const stationTemplate = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
             fs.closeSync(fileDescriptor);
index a7ffe4f4578369d8cdd004e9e2116ac872683032..d8a265c51091bdcce2ad7b8f58bdddbe0478b7fb 100644 (file)
@@ -101,6 +101,8 @@ class Constants {
 
   static WS_UNSUPPORTED_DATA = 1007;
 
+  static OCPP_RESPONSE_ACCEPTED = {status: 'Accepted'};
+  static OCPP_RESPONSE_REJECTED = {status: 'Rejected'};
   static OCPP_SOCKET_TIMEOUT = 60000; // 60 sec
   static OCPP_JSON_CALL_MESSAGE = 2; // Client-to-Server
   static OCPP_JSON_CALL_RESULT_MESSAGE = 3; // Server-to-Client