fix: add charging station at instantiation
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Feb 2024 10:57:51 +0000 (11:57 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Feb 2024 10:57:51 +0000 (11:57 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationWorker.ts

index c8eaf5e44bc70e18844a37ac79390db7a8b845bc..0f4bce43184793c9d3f7c221cb152f26dac5d9eb 100644 (file)
@@ -245,6 +245,8 @@ export class ChargingStation extends EventEmitter {
 
     this.initialize()
 
+    this.add()
+
     this.stationInfo?.autoStart === true && this.start()
   }
 
@@ -652,7 +654,7 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
-  public add (): void {
+  private add (): void {
     this.emit(ChargingStationEvents.added)
   }
 
index 4eb6e6a0aa8d8a13ed7091e8255f35029ed62fce..4fde42c4d3908a368e2424d3a77cbb3180b0d34c 100644 (file)
@@ -19,8 +19,8 @@ export let chargingStationWorker: object
 if (Configuration.workerPoolInUse()) {
   chargingStationWorker = new ThreadWorker<ChargingStationWorkerData>(
     (data?: ChargingStationWorkerData): void => {
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      new ChargingStation(data!.index, data!.templateFile).add()
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, no-new
+      new ChargingStation(data!.index, data!.templateFile)
     }
   )
 } else {
@@ -35,7 +35,6 @@ if (Configuration.workerPoolInUse()) {
                 message.data.index,
                 message.data.templateFile
               )
-              chargingStation.add()
               parentPort?.postMessage({
                 event: WorkerMessageEvents.addedWorkerElement,
                 data: buildChargingStationDataPayload(chargingStation)