build: align URI to access JSON schemas
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 43fb6889fa65cfb48df6d44d599f328398d084ad..92f15e4c20f7c71fdd5f1fffe55723eec306532e 100644 (file)
@@ -796,7 +796,7 @@ export class ChargingStation {
 
   private flushMessageBuffer(): void {
     if (this.messageBuffer.size > 0) {
-      this.messageBuffer.forEach((message) => {
+      for (const message of this.messageBuffer.values()) {
         let beginId: string;
         let commandName: RequestCommand;
         const [messageType] = JSON.parse(message) as OutgoingRequest | Response | ErrorResponse;
@@ -813,7 +813,7 @@ export class ChargingStation {
           )} payload sent: ${message}`
         );
         this.messageBuffer.delete(message);
-      });
+      }
     }
   }
 
@@ -854,27 +854,6 @@ export class ChargingStation {
     return template;
   }
 
-  private warnTemplateKeysDeprecation(stationTemplate: ChargingStationTemplate) {
-    const templateKeys: { key: string; deprecatedKey: string }[] = [
-      { key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' },
-      { key: 'idTagsFile', deprecatedKey: 'authorizationFile' },
-    ];
-    for (const templateKey of templateKeys) {
-      ChargingStationUtils.warnDeprecatedTemplateKey(
-        stationTemplate,
-        templateKey.deprecatedKey,
-        this.templateFile,
-        this.logPrefix(),
-        `Use '${templateKey.key}' instead`
-      );
-      ChargingStationUtils.convertDeprecatedTemplateKey(
-        stationTemplate,
-        templateKey.deprecatedKey,
-        templateKey.key
-      );
-    }
-  }
-
   private getStationInfoFromTemplate(): ChargingStationInfo {
     const stationTemplate: ChargingStationTemplate | undefined = this.getTemplateFromFile();
     if (Utils.isNullOrUndefined(stationTemplate)) {
@@ -887,7 +866,11 @@ export class ChargingStation {
       logger.error(`${this.logPrefix()} ${errorMsg}`);
       throw new BaseError(errorMsg);
     }
-    this.warnTemplateKeysDeprecation(stationTemplate);
+    ChargingStationUtils.warnTemplateKeysDeprecation(
+      this.templateFile,
+      stationTemplate,
+      this.logPrefix()
+    );
     const stationInfo: ChargingStationInfo =
       ChargingStationUtils.stationTemplateToStationInfo(stationTemplate);
     stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate);
@@ -979,7 +962,10 @@ export class ChargingStation {
   private getStationInfo(): ChargingStationInfo {
     const stationInfoFromTemplate: ChargingStationInfo = this.getStationInfoFromTemplate();
     const stationInfoFromFile: ChargingStationInfo | undefined = this.getStationInfoFromFile();
-    // Priority: charging station info from template > charging station info from configuration file > charging station info attribute
+    // Priority:
+    // 1. charging station info from template
+    // 2. charging station info from configuration file
+    // 3. charging station info attribute
     if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) {
       if (this.stationInfo?.infoHash === stationInfoFromFile?.infoHash) {
         return this.stationInfo;
@@ -1337,8 +1323,7 @@ export class ChargingStation {
       }
       if (
         connectorId > 0 &&
-        (this.getConnectorStatus(connectorId)?.transactionStarted === undefined ||
-          this.getConnectorStatus(connectorId)?.transactionStarted === null)
+        Utils.isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionStarted)
       ) {
         this.initializeConnectorStatus(connectorId);
       }
@@ -1862,15 +1847,7 @@ export class ChargingStation {
         // Set default status
         connectorStatus = ConnectorStatusEnum.Available;
       }
-      await this.ocppRequestService.requestHandler<
-        StatusNotificationRequest,
-        StatusNotificationResponse
-      >(
-        this,
-        RequestCommand.STATUS_NOTIFICATION,
-        OCPPServiceUtils.buildStatusNotificationRequest(this, connectorId, connectorStatus)
-      );
-      this.getConnectorStatus(connectorId).status = connectorStatus;
+      await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorStatus);
     }
     if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) {
       await this.ocppRequestService.requestHandler<