Add proper worker set elements reference counting.
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index b3a2e62239303fb6e5af5868570d6de74c8e8795..f646a32c092240f3b3d84df64b6bce709819795b 100644 (file)
@@ -74,9 +74,7 @@ export default class ChargingStation {
     // In case of multiple instances: add instance index to charging station id
     let instanceIndex = process.env.CF_INSTANCE_INDEX ? process.env.CF_INSTANCE_INDEX : 0;
     instanceIndex = instanceIndex > 0 ? instanceIndex : '';
-
     const idSuffix = stationTemplate.nameSuffix ? stationTemplate.nameSuffix : '';
-
     return stationTemplate.fixedName ? stationTemplate.baseName : stationTemplate.baseName + '-' + instanceIndex.toString() + ('000000000' + this.index.toString()).substr(('000000000' + this.index.toString()).length - 4) + idSuffix;
   }
 
@@ -141,6 +139,9 @@ export default class ChargingStation {
         if (Utils.convertToInt(lastConnector) === 0 && this._getUseConnectorId0() && this.stationInfo.Connectors[lastConnector]) {
           this.connectors[lastConnector] = Utils.cloneObject<Connector>(this.stationInfo.Connectors[lastConnector]);
           this.connectors[lastConnector].availability = AvailabilityType.OPERATIVE;
+          if (Utils.isUndefined(this.connectors[lastConnector]?.chargingProfiles)) {
+            this.connectors[lastConnector].chargingProfiles = [];
+          }
         }
       }
       // Generate all connectors
@@ -149,6 +150,9 @@ export default class ChargingStation {
           const randConnectorID = this.stationInfo.randomConnectors ? Utils.getRandomInt(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)) {
+            this.connectors[index].chargingProfiles = [];
+          }
         }
       }
     }
@@ -167,8 +171,7 @@ export default class ChargingStation {
     }
     this.stationInfo.powerDivider = this._getPowerDivider();
     if (this.getEnableStatistics()) {
-      this.statistics = Statistics.getInstance();
-      this.statistics.objName = this.stationInfo.chargingStationId;
+      this.statistics = new Statistics(this.stationInfo.chargingStationId);
       this.performanceObserver = new PerformanceObserver((list) => {
         const entry = list.getEntries()[0];
         this.statistics.logPerformance(entry, Constants.ENTITY_CHARGING_STATION);
@@ -1057,6 +1060,10 @@ export default class ChargingStation {
     logger.debug(this._logPrefix() + ' Heartbeat response received: %j to Heartbeat request: %j', payload, requestPayload);
   }
 
+  handleResponseAuthorize(payload: AuthorizeResponse, requestPayload: AuthorizeRequest): void {
+    logger.debug(this._logPrefix() + ' Authorize response received: %j to Authorize request: %j', payload, requestPayload);
+  }
+
   async handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: Record<string, unknown>): Promise<void> {
     let response;
     // Call