build: bump volta pnpm version
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 0dce59fbea9ea341139a61e40033b77823181791..bcd33ccf0ca17b7f595b2d4f9d38fd6299fc7061 100644 (file)
@@ -232,14 +232,14 @@ export class ChargingStation extends EventEmitter {
         enableStatistics: false,
         remoteAuthorization: true,
         currentOutType: CurrentType.AC,
+        mainVoltageMeterValues: true,
+        phaseLineToLineVoltageMeterValues: false,
+        customValueLimitationMeterValues: true,
         ocppStrictCompliance: true,
         outOfOrderEndMeterValues: false,
         beginEndMeterValues: false,
         meteringPerTransaction: true,
         transactionDataMeterValues: false,
-        mainVoltageMeterValues: true,
-        phaseLineToLineVoltageMeterValues: false,
-        customValueLimitationMeterValues: true,
         supervisionUrlOcppConfiguration: false,
         supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl,
         ocppVersion: OCPPVersion.VERSION_16,
@@ -513,7 +513,7 @@ export class ChargingStation extends EventEmitter {
 
   public setSupervisionUrl(url: string): void {
     if (
-      this.stationInfo?.supervisionUrlOcppConfiguration &&
+      this.stationInfo?.supervisionUrlOcppConfiguration === true &&
       isNotEmptyString(this.stationInfo?.supervisionUrlOcppKey)
     ) {
       setConfigurationKeyValue(this, this.stationInfo.supervisionUrlOcppKey!, url);
@@ -1115,6 +1115,7 @@ export class ChargingStation extends EventEmitter {
     stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate);
     stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
     createSerialNumber(stationTemplate, stationInfo);
+    stationInfo.voltageOut = this.getVoltageOut(stationInfo);
     if (isNotEmptyArray(stationTemplate?.power)) {
       stationTemplate.power = stationTemplate.power as number[];
       const powerArrayRandomIndex = Math.floor(secureRandom() * stationTemplate.power.length);
@@ -1192,7 +1193,7 @@ export class ChargingStation extends EventEmitter {
     }
   }
 
-  private handleUnsupportedVersion(version: OCPPVersion) {
+  private handleUnsupportedVersion(version: OCPPVersion | undefined) {
     const errorMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
     logger.error(`${this.logPrefix()} ${errorMsg}`);
     throw new BaseError(errorMsg);
@@ -1249,6 +1250,11 @@ export class ChargingStation extends EventEmitter {
     this.ocppConfiguration = this.getOcppConfiguration();
     this.initializeOcppConfiguration();
     this.initializeOcppServices();
+    this.once(ChargingStationEvents.accepted, () => {
+      this.startMessageSequence().catch((error) => {
+        logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error);
+      });
+    });
     if (this.stationInfo?.autoRegister === true) {
       this.bootNotificationResponse = {
         currentTime: new Date(),
@@ -1735,9 +1741,9 @@ export class ChargingStation extends EventEmitter {
       logger.info(
         `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`,
       );
+      let registrationRetryCount = 0;
       if (this.isRegistered() === false) {
         // Send BootNotification
-        let registrationRetryCount = 0;
         do {
           this.bootNotificationResponse = await this.ocppRequestService.requestHandler<
             BootNotificationRequest,
@@ -1763,11 +1769,10 @@ export class ChargingStation extends EventEmitter {
         this.emit(ChargingStationEvents.registered);
         if (this.inAcceptedState() === true) {
           this.emit(ChargingStationEvents.accepted);
-          await this.startMessageSequence();
         }
       } else {
         logger.error(
-          `${this.logPrefix()} Registration failure: max retries reached or retry disabled (${this
+          `${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${this
             .stationInfo?.registrationMaxRetries})`,
         );
       }
@@ -2037,7 +2042,7 @@ export class ChargingStation extends EventEmitter {
 
   private getPowerDivider(): number {
     let powerDivider = this.hasEvses ? this.getNumberOfEvses() : this.getNumberOfConnectors();
-    if (this.stationInfo?.powerSharedByConnectors) {
+    if (this.stationInfo?.powerSharedByConnectors === true) {
       powerDivider = this.getNumberOfRunningTransactions();
     }
     return powerDivider;
@@ -2152,12 +2157,12 @@ export class ChargingStation extends EventEmitter {
     this.stopWebSocketPing();
     // Stop heartbeat
     this.stopHeartbeat();
-    // Stop ongoing transactions
-    stopTransactions && (await this.stopRunningTransactions(reason));
     // Stop the ATG
     if (this.automaticTransactionGenerator?.started === true) {
       this.stopAutomaticTransactionGenerator();
     }
+    // Stop ongoing transactions
+    stopTransactions && (await this.stopRunningTransactions(reason));
     if (this.hasEvses) {
       for (const [evseId, evseStatus] of this.evses) {
         if (evseId > 0) {