Cleanups.
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.js
index 38e9f582c1661fcb765e5d6c4da819ad579c09af..b0a461fadd6f8269af2c902f727dccbecffc40a7 100644 (file)
@@ -336,7 +336,7 @@ class ChargingStation {
 
   sendError(messageId, err) {
     // Check exception: only OCPP error are accepted
-    const error = (err instanceof OCPPError ? err : new OCPPError(Constants.OCPP_ERROR_INTERNAL_ERROR, err.message));
+    const error = err instanceof OCPPError ? err : new OCPPError(Constants.OCPP_ERROR_INTERNAL_ERROR, err.message);
     // Send error
     return this.sendMessage(messageId, error, Constants.OCPP_JSON_CALL_ERROR_MESSAGE);
   }
@@ -514,8 +514,8 @@ class ChargingStation {
           this.sendStatusNotification(requestPayload.connectorId, 'Charging');
           const configuredMeterValueSampleInterval = this._configuration.configurationKey.find((value) => value.key === 'MeterValueSampleInterval');
           this.startMeterValues(requestPayload.connectorId,
-              (configuredMeterValueSampleInterval ? configuredMeterValueSampleInterval.value * 1000 : 60000),
-              this);
+            configuredMeterValueSampleInterval ? configuredMeterValueSampleInterval.value * 1000 : 60000,
+            this);
         }
       }
     } else {
@@ -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) {
@@ -587,7 +607,7 @@ class ChargingStation {
   }
 
   async handleRemoteStartTransaction(commandPayload) {
-    const transactionConnectorID = (commandPayload.connectorId ? commandPayload.connectorId : '1');
+    const transactionConnectorID = commandPayload.connectorId ? commandPayload.connectorId : '1';
     if (this.hasAuthorizedTags() && this._getLocalAuthListEnabled() && this._getAuthorizeRemoteTxRequests()) {
       // Check if authorized
       if (this._authorizedTags.find((value) => value === commandPayload.idTag)) {
@@ -665,7 +685,7 @@ class ChargingStation {
           sampledValueLcl.sampledValue[index].value = Math.floor(Math.random() * 100) + 1;
           if (sampledValueLcl.sampledValue[index].value > 100) {
             logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
-              (sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'default') +
+              sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register' +
               ', value: ' + sampledValueLcl.sampledValue[index].value);
           }
         } else {
@@ -683,7 +703,7 @@ class ChargingStation {
           sampledValueLcl.sampledValue[index].value = connector.lastConsumptionValue;
           if (sampledValueLcl.sampledValue[index].value > (self._stationInfo.maxPower * 3600 / interval) || sampledValueLcl.sampledValue[index].value < 500) {
             logger.info(self._basicFormatLog() + ' MeterValues measurand: ' +
-              (sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'default') +
+              sampledValueLcl.sampledValue[index].measurand ? sampledValueLcl.sampledValue[index].measurand : 'Energy.Active.Import.Register' +
               ', value: ' + sampledValueLcl.sampledValue[index].value + '/' + (self._stationInfo.maxPower * 3600 / interval));
           }
         }