From: Jérôme Benoit Date: Fri, 16 Oct 2020 22:23:10 +0000 (+0200) Subject: Fix type comparisons X-Git-Tag: v1.0.1-0~299 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=def3d48ec64cde4fb7890494dc1d8028098d8e8d;p=e-mobility-charging-stations-simulator.git Fix type comparisons Signed-off-by: Jérôme Benoit --- 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; }