From 72766a82a1372713a48d9e7143a0348d7fd56a29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 18 Oct 2020 01:19:55 +0200 Subject: [PATCH] Cleanups. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.js | 12 +++++------ src/charging-station/OcppError.js | 2 +- src/utils/Constants.js | 2 +- src/utils/Statistics.js | 8 ++++---- src/utils/Utils.js | 27 ++++++++++++++----------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index 91232e5f..b0a461fa 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -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 { @@ -607,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)) { @@ -685,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 { @@ -703,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)); } } diff --git a/src/charging-station/OcppError.js b/src/charging-station/OcppError.js index 1793eae3..89ead59a 100644 --- a/src/charging-station/OcppError.js +++ b/src/charging-station/OcppError.js @@ -8,7 +8,7 @@ class OCPPError extends Error { Object.setPrototypeOf(this, OCPPError.prototype); // for instanceof - Error.captureStackTrace ? (Error.captureStackTrace(this, this.constructor)) : (this.stack = (new Error()).stack); + Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : (this.stack = (new Error()).stack); } } diff --git a/src/utils/Constants.js b/src/utils/Constants.js index 3c7e13a0..b5b55cc3 100644 --- a/src/utils/Constants.js +++ b/src/utils/Constants.js @@ -32,7 +32,7 @@ class Constants { static ENTITY_LOGGING = 'Logging'; static ENTITY_PRICING = 'Pricing'; - static NOTIF_TYPE_CHARGING_STATION_CONFIGURATION = 'Configuration'; + static NOTIFICATION_TYPE_CHARGING_STATION_CONFIGURATION = 'Configuration'; static ACTION_READ = 'Read'; static ACTION_CREATE = 'Create'; diff --git a/src/utils/Statistics.js b/src/utils/Statistics.js index edbec262..bc340580 100644 --- a/src/utils/Statistics.js +++ b/src/utils/Statistics.js @@ -52,10 +52,10 @@ class Statistics { if (currentStatistics) { // Update current statistics timers - currentStatistics.countTime = (currentStatistics.countTime ? currentStatistics.countTime + 1 : 1); - currentStatistics.minTime = (currentStatistics.minTime ? (currentStatistics.minTime > duration ? duration : currentStatistics.minTime) : duration); - currentStatistics.maxTime = (currentStatistics.maxTime ? (currentStatistics.maxTime < duration ? duration : currentStatistics.maxTime) : duration); - currentStatistics.totalTime = (currentStatistics.totalTime ? currentStatistics.totalTime + duration : duration); + currentStatistics.countTime = currentStatistics.countTime ? currentStatistics.countTime + 1 : 1; + currentStatistics.minTime = currentStatistics.minTime ? (currentStatistics.minTime > duration ? duration : currentStatistics.minTime) : duration; + currentStatistics.maxTime = currentStatistics.maxTime ? (currentStatistics.maxTime < duration ? duration : currentStatistics.maxTime) : duration; + currentStatistics.totalTime = currentStatistics.totalTime ? currentStatistics.totalTime + duration : duration; currentStatistics.avgTime = currentStatistics.totalTime / currentStatistics.countTime; } } diff --git a/src/utils/Utils.js b/src/utils/Utils.js index 446f5241..216790bc 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -74,30 +74,33 @@ class Utils { return changedID; } - static convertToInt(id) { - let changedID = id; - if (!id) { + static convertToInt(value) { + let changedValue = value; + if (!value) { return 0; } + if (Number.isSafeInteger(value)) { + return value; + } // Check - if (typeof id === 'string') { + if (typeof value === 'string') { // Create Object - changedID = parseInt(id); + changedValue = parseInt(value); } - return changedID; + return changedValue; } - static convertToFloat(id) { - let changedID = id; - if (!id) { + static convertToFloat(value) { + let changedValue = value; + if (!value) { return 0; } // Check - if (typeof id === 'string') { + if (typeof value === 'string') { // Create Object - changedID = parseFloat(id); + changedValue = parseFloat(value); } - return changedID; + return changedValue; } static convertToBoolean(value) { -- 2.34.1