Silence one eslint warning
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 5c8ec1e48d9ad7ae112340f4a553abad3cb0f37a..c4d9abb610f1dd8b73fa1b169a06078d2ff52f64 100644 (file)
@@ -6,7 +6,7 @@ import path from 'path';
 import { URL } from 'url';
 import { parentPort } from 'worker_threads';
 
-import WebSocket, { Data, RawData } from 'ws';
+import WebSocket, { type RawData } from 'ws';
 
 import BaseError from '../exception/BaseError';
 import OCPPError from '../exception/OCPPError';
@@ -796,7 +796,7 @@ export default class ChargingStation {
   private getStationInfoFromTemplate(): ChargingStationInfo {
     const stationTemplate: ChargingStationTemplate = this.getTemplateFromFile();
     if (Utils.isNullOrUndefined(stationTemplate)) {
-      const errorMsg = 'Failed to read charging station template file';
+      const errorMsg = `Failed to read charging station template file ${this.templateFile}`;
       logger.error(`${this.logPrefix()} ${errorMsg}`);
       throw new BaseError(errorMsg);
     }
@@ -818,6 +818,21 @@ export default class ChargingStation {
       'supervisionUrl',
       'supervisionUrls'
     );
+    const firmwareVersionRegExp = stationTemplate.firmwareVersionPattern
+      ? new RegExp(stationTemplate.firmwareVersionPattern)
+      : Constants.SEMVER_REGEXP;
+    if (
+      stationTemplate.firmwareVersion &&
+      firmwareVersionRegExp.test(stationTemplate.firmwareVersion) === false
+    ) {
+      logger.warn(
+        `${this.logPrefix()} Firmware version '${
+          stationTemplate.firmwareVersion
+        }' in template file ${
+          this.templateFile
+        } does not match regular expression '${firmwareVersionRegExp.toString()}'`
+      );
+    }
     const stationInfo: ChargingStationInfo =
       ChargingStationUtils.stationTemplateToStationInfo(stationTemplate);
     stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate);
@@ -1387,7 +1402,7 @@ export default class ChargingStation {
     }
   }
 
-  private async onClose(code: number, reason: string): Promise<void> {
+  private async onClose(code: number, reason: Buffer): Promise<void> {
     switch (code) {
       // Normal close
       case WebSocketCloseEventStatusCode.CLOSE_NORMAL:
@@ -1395,7 +1410,7 @@ export default class ChargingStation {
         logger.info(
           `${this.logPrefix()} WebSocket normally closed with status '${Utils.getWebSocketCloseEventStatusString(
             code
-          )}' and reason '${reason}'`
+          )}' and reason '${reason.toString()}'`
         );
         this.autoReconnectRetryCount = 0;
         break;
@@ -1404,7 +1419,7 @@ export default class ChargingStation {
         logger.error(
           `${this.logPrefix()} WebSocket abnormally closed with status '${Utils.getWebSocketCloseEventStatusString(
             code
-          )}' and reason '${reason}'`
+          )}' and reason '${reason.toString()}'`
         );
         this.started === true && (await this.reconnect());
         break;
@@ -1412,7 +1427,7 @@ export default class ChargingStation {
     parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
   }
 
-  private async onMessage(data: Data): Promise<void> {
+  private async onMessage(data: RawData): Promise<void> {
     let messageType: number;
     let messageId: string;
     let commandName: IncomingRequestCommand;
@@ -1890,9 +1905,7 @@ export default class ChargingStation {
   }
 
   private getConfiguredSupervisionUrl(): URL {
-    const supervisionUrls = Utils.cloneObject<string | string[]>(
-      this.stationInfo.supervisionUrls ?? Configuration.getSupervisionUrls()
-    );
+    const supervisionUrls = this.stationInfo.supervisionUrls ?? Configuration.getSupervisionUrls();
     if (!Utils.isEmptyArray(supervisionUrls)) {
       switch (Configuration.getSupervisionUrlDistribution()) {
         case SupervisionUrlDistribution.ROUND_ROBIN: