Make getConfiguration response smarter.
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 17 Oct 2020 22:46:53 +0000 (00:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 17 Oct 2020 22:46:53 +0000 (00:46 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/assets/station-templates/abb.station-template.json
src/charging-station/ChargingStation.js
src/utils/Utils.js

index f256c37e61d059141b4dded5b081140076985ee4..1fef0e8abccefb9d44d9c5bcf981fb2e4f0d8ac5 100644 (file)
         "key": "AuthorizeRemoteTxRequests",
         "readonly": false,
         "value": false
+      },
+      {
+        "key": "VendorKey",
+        "readonly": false,
+        "value": "VendorValue",
+        "visible": false
       }
     ]
   },
index 38e9f582c1661fcb765e5d6c4da819ad579c09af..91232e5f0c172e404ea7cf09facf01c2a705761c 100644 (file)
@@ -531,22 +531,22 @@ class ChargingStation {
 
   handleResponseStopTransaction(payload, requestPayload) {
     if (payload.idTagInfo && payload.idTagInfo.status) {
-      logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: ' + payload.idTagInfo.status );
+      logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: ' + payload.idTagInfo.status);
     } else {
       logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: Unknown');
     }
   }
 
-  handleResponseStatusNotification(payload) {
-    logger.debug(this._basicFormatLog() + ' Status notification response received: %j', payload);
+  handleResponseStatusNotification(payload, requestPayload) {
+    logger.debug(this._basicFormatLog() + ' Status notification response received: %j to status notification request: %j', payload, requestPayload);
   }
 
-  handleResponseMeterValues(payload) {
-    logger.debug(this._basicFormatLog() + ' MeterValues response received: %j', payload);
+  handleResponseMeterValues(payload, requestPayload) {
+    logger.debug(this._basicFormatLog() + ' MeterValues response received: %j to MeterValues request: %j', payload, requestPayload);
   }
 
-  handleResponseHeartbeat(payload) {
-    logger.debug(this._basicFormatLog() + ' Heartbeat response received: %j', payload);
+  handleResponseHeartbeat(payload, requestPayload) {
+    logger.debug(this._basicFormatLog() + ' Heartbeat response received: %j to Heartbeat request: %j', payload, requestPayload);
   }
 
   async handleRequest(messageId, commandName, commandPayload) {
@@ -560,7 +560,7 @@ class ChargingStation {
       } catch (error) {
         // Log
         logger.error(this._basicFormatLog() + ' Handle request error: ' + error);
-        // Send back response to inform back end
+        // Send back response to inform backend
         await this.sendError(messageId, error);
       }
     } else {
@@ -573,7 +573,27 @@ class ChargingStation {
   }
 
   async handleGetConfiguration(commandPayload) {
-    return this._configuration;
+    const configurationKey = [];
+    const unknownKey = [];
+    for (const configuration of this._configuration.configurationKey) {
+      if (Utils.isUndefined(configuration.visible)) {
+        configuration.visible = true;
+      } else {
+        configuration.visible = Utils.convertToBoolean(configuration.visible);
+      }
+      if (!configuration.visible) {
+        continue;
+      }
+      configurationKey.push({
+        key: configuration.key,
+        readonly: configuration.readonly,
+        value: configuration.value,
+      });
+    }
+    return {
+      configurationKey,
+      unknownKey,
+    };
   }
 
   async handleChangeConfiguration(commandPayload) {
index 5f467feaa6b70035fa75dbd2ce2e7e228c1c93bc..446f524150c1cff7ddadc00863c35fc547f4cb12 100644 (file)
@@ -135,6 +135,13 @@ class Utils {
   static cloneJSonDocument(jsonDocument) {
     return JSON.parse(JSON.stringify(jsonDocument));
   }
+
+  static isUndefined(value) {
+    if (typeof value === 'undefined') {
+      return true;
+    }
+    return false;
+  }
 }
 
 module.exports = Utils;