Untangle charging station worker types from the generic ones
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 79336707c621f0785e14baa78f860f4bbb260a9a..5b5ac56e4d79e8ced4d3e15758f7b554f331550e 100644 (file)
@@ -84,7 +84,7 @@ export default class ChargingStation {
     return this.bootNotificationRequest;
   }
 
-  public getRandomTagId(): string {
+  public getRandomIdTag(): string {
     const index = Math.floor(Utils.secureRandom() * this.authorizedTags.length);
     return this.authorizedTags[index];
   }
@@ -525,7 +525,7 @@ export default class ChargingStation {
       // Generate all connectors
       if ((this.stationInfo.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) > 0) {
         for (let index = 1; index <= maxConnectors; index++) {
-          const randConnectorId = this.stationInfo.randomConnectors ? Utils.getRandomInt(Utils.convertToInt(lastConnector), 1) : index;
+          const randConnectorId = this.stationInfo.randomConnectors ? Utils.getRandomInteger(Utils.convertToInt(lastConnector), 1) : index;
           this.connectors[index] = Utils.cloneObject<Connector>(this.stationInfo.Connectors[randConnectorId]);
           this.connectors[index].availability = AvailabilityType.OPERATIVE;
           if (Utils.isUndefined(this.connectors[lastConnector]?.chargingProfiles)) {
@@ -538,7 +538,7 @@ export default class ChargingStation {
     delete this.stationInfo.Connectors;
     // Initialize transaction attributes on connectors
     for (const connector in this.connectors) {
-      if (Utils.convertToInt(connector) > 0 && !this.getConnector(Utils.convertToInt(connector)).transactionStarted) {
+      if (Utils.convertToInt(connector) > 0 && !this.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
         this.initTransactionAttributesOnConnector(Utils.convertToInt(connector));
       }
     }
@@ -766,7 +766,7 @@ export default class ChargingStation {
   private getNumberOfRunningTransactions(): number {
     let trxCount = 0;
     for (const connector in this.connectors) {
-      if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionStarted) {
+      if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
         trxCount++;
       }
     }
@@ -880,10 +880,10 @@ export default class ChargingStation {
     if (this.stationInfo.AutomaticTransactionGenerator.enable &&
       this.automaticTransactionGenerator &&
       this.automaticTransactionGenerator.started) {
-      await this.automaticTransactionGenerator.stop(reason);
+      this.automaticTransactionGenerator.stop();
     } else {
       for (const connector in this.connectors) {
-        if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionStarted) {
+        if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
           const transactionId = this.getConnector(Utils.convertToInt(connector)).transactionId;
           await this.ocppRequestService.sendStopTransaction(transactionId, this.getEnergyActiveImportRegisterByTransactionId(transactionId),
             this.getTransactionIdTag(transactionId), reason);
@@ -1003,7 +1003,7 @@ export default class ChargingStation {
 
   private startStationTemplateFileMonitoring(): void {
     try {
-      fs.watch(this.stationTemplateFile, async (event, filename): Promise<void> => {
+      fs.watch(this.stationTemplateFile, (event, filename): void => {
         if (filename && event === 'change') {
           try {
             logger.debug(this.logPrefix() + ' Template file ' + this.stationTemplateFile + ' have changed, reload');
@@ -1012,7 +1012,7 @@ export default class ChargingStation {
             // Restart the ATG
             if (!this.stationInfo.AutomaticTransactionGenerator.enable &&
                 this.automaticTransactionGenerator) {
-              await this.automaticTransactionGenerator.stop();
+              this.automaticTransactionGenerator.stop();
             }
             this.startAutomaticTransactionGenerator();
             if (this.getEnableStatistics()) {
@@ -1045,7 +1045,7 @@ export default class ChargingStation {
       this.stationInfo.AutomaticTransactionGenerator.stopOnConnectionFailure &&
       this.automaticTransactionGenerator &&
       this.automaticTransactionGenerator.started) {
-      await this.automaticTransactionGenerator.stop();
+      this.automaticTransactionGenerator.stop();
     }
     if (this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries() || this.getAutoReconnectMaxRetries() === -1) {
       this.autoReconnectRetryCount++;