From def3d48ec64cde4fb7890494dc1d8028098d8e8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 17 Oct 2020 00:23:10 +0200 Subject: [PATCH] Fix type comparisons MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/assets/station/abb.station | 3 ++- src/assets/station/evlink.station | 3 ++- src/assets/station/keba.station | 3 ++- src/assets/station/schneider-imredd.station | 3 ++- src/assets/station/schneider.station | 3 ++- src/assets/station/siemens.mougins69.station | 3 ++- src/assets/station/virtual-simple-atg.station | 3 ++- src/assets/station/virtual-simple.station | 3 ++- src/assets/station/virtual.station | 3 ++- .../AutomaticTransactionGenerator.js | 2 +- src/charging-station/ChargingStation.js | 20 +++++++++++-------- 11 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/assets/station/abb.station b/src/assets/station/abb.station index 67b4214f..1335a777 100644 --- a/src/assets/station/abb.station +++ b/src/assets/station/abb.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 2}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 30}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/evlink.station b/src/assets/station/evlink.station index 2424c0e5..ac8418c3 100644 --- a/src/assets/station/evlink.station +++ b/src/assets/station/evlink.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 1}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 20}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/keba.station b/src/assets/station/keba.station index 6a61cc3b..ec6cc13b 100644 --- a/src/assets/station/keba.station +++ b/src/assets/station/keba.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 2}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 30}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/schneider-imredd.station b/src/assets/station/schneider-imredd.station index ade470fa..a8626905 100644 --- a/src/assets/station/schneider-imredd.station +++ b/src/assets/station/schneider-imredd.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 2}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 20}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/schneider.station b/src/assets/station/schneider.station index ade470fa..a8626905 100644 --- a/src/assets/station/schneider.station +++ b/src/assets/station/schneider.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 2}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 20}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/siemens.mougins69.station b/src/assets/station/siemens.mougins69.station index aa58d1f2..548099d2 100644 --- a/src/assets/station/siemens.mougins69.station +++ b/src/assets/station/siemens.mougins69.station @@ -10,8 +10,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 2}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 30}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/virtual-simple-atg.station b/src/assets/station/virtual-simple-atg.station index d0da727b..f6f7c27b 100644 --- a/src/assets/station/virtual-simple-atg.station +++ b/src/assets/station/virtual-simple-atg.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 3}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 30}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/virtual-simple.station b/src/assets/station/virtual-simple.station index 107cb9eb..939e5c22 100644 --- a/src/assets/station/virtual-simple.station +++ b/src/assets/station/virtual-simple.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 3}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 30}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/assets/station/virtual.station b/src/assets/station/virtual.station index 107ad594..0bf089b6 100644 --- a/src/assets/station/virtual.station +++ b/src/assets/station/virtual.station @@ -9,8 +9,9 @@ "randomConnectors": false, "Configuration": { "configurationKey": [ { "key": "NumberOfConnectors", "readonly": true, "value": 9}, - { "key": "param1", "readonly": false, "value": "test"}, { "key": "MeterValueSampleInterval", "readonly": false, "value": 30}, + { "key": "SupportedFeatureProfiles", "readonly": true, "value": "Core,LocalAuthListManagement"}, + { "key": "LocalAuthListEnabled", "readonly": false, "value": false}, { "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false} ] }, diff --git a/src/charging-station/AutomaticTransactionGenerator.js b/src/charging-station/AutomaticTransactionGenerator.js index 6b3e2e76..05a11044 100644 --- a/src/charging-station/AutomaticTransactionGenerator.js +++ b/src/charging-station/AutomaticTransactionGenerator.js @@ -88,7 +88,7 @@ class AutomaticTransactionGenerator { // eslint-disable-next-line class-methods-use-this async startTransaction(connectorId, self) { - if (self._chargingStation.isAuthorizationRequested()) { + if (self._chargingStation.hasAuthorizationKeys()) { const tagId = self._chargingStation.getRandomTagId(); logger.info(self._basicFormatLog(connectorId) + ' start transaction for tagID ' + tagId); return self._chargingStation.sendStartTransaction(connectorId, tagId); diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index 0411a1a1..0fccef48 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -75,6 +75,11 @@ class ChargingStation { return authorizeRemoteTxRequests ? Utils.convertToBoolean(authorizeRemoteTxRequests.value) : false; } + _getLocalAuthListEnabled() { + const localAuthListEnabled = this._configuration.configurationKey.find((configElement) => configElement.key === 'LocalAuthListEnabled'); + return localAuthListEnabled ? Utils.convertToBoolean(localAuthListEnabled.value) : false; + } + _buildChargingStation(index, stationTemplate) { if (Array.isArray(stationTemplate.power)) { stationTemplate.maxPower = stationTemplate.power[Math.floor(Math.random() * stationTemplate.power.length)]; @@ -89,15 +94,12 @@ class ChargingStation { logger.info(this._basicFormatLog() + ' Will communicate with ' + this._supervisionUrl); this._url = this._supervisionUrl + '/' + this._stationInfo.name; this._wsConnection = new WebSocket(this._url, 'ocpp1.6'); - if (this._authorizationFile !== '') { + if (this._authorizationFile) { try { // load file const fileDescriptor = fs.openSync(this._authorizationFile, 'r'); this._authorizedKeys = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8')); fs.closeSync(fileDescriptor); - // get remote authorization logic - // FIXME: move to the constructor - this._authorizeRemoteTxRequests = this._getAuthorizeRemoteTxRequests(); // monitor authorization file // eslint-disable-next-line no-unused-vars fs.watchFile(this._authorizationFile, (current, previous) => { @@ -113,6 +115,8 @@ class ChargingStation { } catch (error) { logger.error(this._basicFormatLog() + ' Authorization file error: ' + error); } + } else { + logger.info(this._basicFormatLog() + ' No authorization file given in template ' + this._stationInfo.baseName); } // Handle Socket incoming messages this._wsConnection.on('message', this.onMessage.bind(this)); @@ -407,7 +411,7 @@ class ChargingStation { if (payload.idTagInfo.status === 'Accepted') { for (const connector in this._connectors) { - if (Utils.convertToInt(connector) === requestPayload.connectorId) { + if (Utils.convertToInt(connector) === Utils.convertToInt(requestPayload.connectorId)) { this._connectors[connector].transactionStarted = true; this._connectors[connector].transactionId = payload.transactionId; this._connectors[connector].lastConsumptionValue = 0; @@ -423,7 +427,7 @@ class ChargingStation { } else { logger.error(this._basicFormatLog() + ' Starting transaction id ' + payload.transactionId + ' REJECTED with status ' + payload.idTagInfo.status + ', idTag ' + requestPayload.idTag); for (const connector in this._connectors) { - if (Utils.convertToInt(connector) === requestPayload.connectorId) { + if (Utils.convertToInt(connector) === Utils.convertToInt(requestPayload.connectorId)) { this._resetTransactionOnConnector(connector); } } @@ -502,7 +506,7 @@ class ChargingStation { async handleRemoteStartTransaction(commandPayload) { const transactionConnectorID = (commandPayload.connectorId ? commandPayload.connectorId : '1'); - if (this.isAuthorizationRequested() && this._authorizeRemoteTxRequests) { + if (this.hasAuthorizationKeys() && this._getLocalAuthListEnabled() && this._getAuthorizeRemoteTxRequests()) { // Check if authorized if (this._authorizedKeys.find((value) => value === commandPayload.idTag)) { // Authorization successful start transaction @@ -640,7 +644,7 @@ class ChargingStation { return Constants.OCPP_RESPONSE_ACCEPTED; } - isAuthorizationRequested() { + hasAuthorizationKeys() { return this._authorizedKeys && this._authorizedKeys.length > 0; } -- 2.34.1