Fix type comparisons
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 16 Oct 2020 22:23:10 +0000 (00:23 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 16 Oct 2020 22:23:10 +0000 (00:23 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/assets/station/abb.station
src/assets/station/evlink.station
src/assets/station/keba.station
src/assets/station/schneider-imredd.station
src/assets/station/schneider.station
src/assets/station/siemens.mougins69.station
src/assets/station/virtual-simple-atg.station
src/assets/station/virtual-simple.station
src/assets/station/virtual.station
src/charging-station/AutomaticTransactionGenerator.js
src/charging-station/ChargingStation.js

index 67b4214fe8ae3ed51215fd25e23a62754d1085b2..1335a777b9e7bc2b7b04bc961041fb2728121b1a 100644 (file)
@@ -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}
         ]
     },
index 2424c0e5ae66887caa49a443adf411a62dadfac6..ac8418c3124cee037b1a1393c2fb455a4c6f2d75 100644 (file)
@@ -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}
         ]
     },
index 6a61cc3bced3788ad0778a93093ce631889e6c7e..ec6cc13bebd4901f42888b3ea5cf69b49491f9f0 100644 (file)
@@ -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}
         ]
     },
index ade470fa229de99464760ce1768f941dea05c8ae..a86269053540243182a831344773177a8a218f14 100644 (file)
@@ -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}
         ]
     },
index ade470fa229de99464760ce1768f941dea05c8ae..a86269053540243182a831344773177a8a218f14 100644 (file)
@@ -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}
         ]
     },
index aa58d1f28ebc941d58de27a1a9ddabed7368be4e..548099d230fe972b8c31a9463b26a8e8c13765aa 100644 (file)
@@ -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}
         ]
     },
index d0da727b57597912132b70dac1a2b8425b4cf2c0..f6f7c27bd7b3f3a15cf9ba65777a94221c2c3f71 100644 (file)
@@ -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}
         ]
     },
index 107cb9eb83ce15053e0851ab25ab5041d4687ceb..939e5c2296cede6755c8157153d428fb8490eed5 100644 (file)
@@ -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}
         ]
     },
index 107ad594cb887461a328693ff9aba0985c88d33a..0bf089b608001cb72798d58cc175fc016f2eff3d 100644 (file)
@@ -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}
         ]
     },
index 6b3e2e76cac1c1f9bfe7f930ec80e596c436d3e1..05a11044f54064a6454dd1adeaa89f7708d7de15 100644 (file)
@@ -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);
index 0411a1a1f12c88bb457b4246f10d7b30131e37a9..0fccef4895d0b27a4abb8d51a370269dcb3a81f6 100644 (file)
@@ -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;
   }