Move hashId to stationInfo
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 30 Aug 2022 09:47:24 +0000 (11:47 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 30 Aug 2022 09:47:24 +0000 (11:47 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
13 files changed:
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/MessageChannelUtils.ts
src/types/ChargingStationInfo.ts
src/types/ChargingStationWorker.ts
src/ui/web/src/components/charging-stations/CSConnector.vue
src/ui/web/src/components/charging-stations/CSData.vue
src/ui/web/src/components/charging-stations/CSTable.vue
src/ui/web/src/types/ChargingStationType.ts
src/worker/WorkerUtils.ts

index a6408d2bd7f4366f16880cdbb421ba8ffb46469a..d9f0e249047c8c10168e0fb92115d0b61269015c 100644 (file)
@@ -49,16 +49,16 @@ export default class AutomaticTransactionGenerator {
     automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration,
     chargingStation: ChargingStation
   ): AutomaticTransactionGenerator {
-    if (!AutomaticTransactionGenerator.instances.has(chargingStation.hashId)) {
+    if (!AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId)) {
       AutomaticTransactionGenerator.instances.set(
-        chargingStation.hashId,
+        chargingStation.stationInfo.hashId,
         new AutomaticTransactionGenerator(
           automaticTransactionGeneratorConfiguration,
           chargingStation
         )
       );
     }
-    return AutomaticTransactionGenerator.instances.get(chargingStation.hashId);
+    return AutomaticTransactionGenerator.instances.get(chargingStation.stationInfo.hashId);
   }
 
   public start(): void {
index d6bf3f37da35a767ad70c3ae38d1c783c1daa73b..277558360ad732b498dd7d8b20b4476521772d82 100644 (file)
@@ -223,17 +223,17 @@ export class Bootstrap {
   }
 
   private workerEventStarted(data: ChargingStationData) {
-    this.uiServer?.chargingStations.set(data.hashId, data);
+    this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
     ++this.numberOfStartedChargingStations;
   }
 
   private workerEventStopped(data: ChargingStationData) {
-    this.uiServer?.chargingStations.set(data.hashId, data);
+    this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
     --this.numberOfStartedChargingStations;
   }
 
   private workerEventUpdated(data: ChargingStationData) {
-    this.uiServer?.chargingStations.set(data.hashId, data);
+    this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
   }
 
   private workerEventPerformanceStatistics = (data: Statistics) => {
index a47bc68182a77de166b1dc9fd273a7d31d59265b..66146be92afc4f80224893752037f611e9b7fc79 100644 (file)
@@ -84,7 +84,6 @@ import type OCPPRequestService from './ocpp/OCPPRequestService';
 import SharedLRUCache from './SharedLRUCache';
 
 export default class ChargingStation {
-  public hashId!: string;
   public readonly templateFile: string;
   public authorizedTagsCache: AuthorizedTagsCache;
   public stationInfo!: ChargingStationInfo;
@@ -841,6 +840,7 @@ export default class ChargingStation {
     );
     const stationInfo: ChargingStationInfo =
       ChargingStationUtils.stationTemplateToStationInfo(stationTemplate);
+    stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate);
     stationInfo.chargingStationId = ChargingStationUtils.getChargingStationId(
       this.index,
       stationTemplate
@@ -950,20 +950,19 @@ export default class ChargingStation {
   }
 
   private initialize(): void {
-    this.hashId = ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile());
-    logger.info(`${this.logPrefix()} Charging station hashId '${this.hashId}'`);
+    this.stationInfo = this.getStationInfo();
+    this.saveStationInfo();
+    logger.info(`${this.logPrefix()} Charging station hashId '${this.stationInfo.hashId}'`);
     this.configurationFile = path.join(
       path.dirname(this.templateFile.replace('station-templates', 'configurations')),
-      this.hashId + '.json'
+      this.stationInfo.hashId + '.json'
     );
-    this.stationInfo = this.getStationInfo();
-    this.saveStationInfo();
     // Avoid duplication of connectors related information in RAM
     this.stationInfo?.Connectors && delete this.stationInfo.Connectors;
     this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl();
     if (this.getEnableStatistics()) {
       this.performanceStatistics = PerformanceStatistics.getInstance(
-        this.hashId,
+        this.stationInfo.hashId,
         this.stationInfo.chargingStationId,
         this.configuredSupervisionUrl
       );
index 4f058b725fd6645a3bd4753efb5e85102564f1f3..60e143faaa51c55a470b453fe623d3379dc12370 100644 (file)
@@ -240,7 +240,7 @@ export class ChargingStationUtils {
     delete stationTemplate.chargeBoxSerialNumberPrefix;
     delete stationTemplate.chargePointSerialNumberPrefix;
     delete stationTemplate.meterSerialNumberPrefix;
-    return stationTemplate;
+    return stationTemplate as unknown as ChargingStationInfo;
   }
 
   public static createStationInfoHash(stationInfo: ChargingStationInfo): void {
index 6fc700d29c8d2f322fffffd32150e592a2e02898..64332533d4dfc606f9b551e5f3f0de8aa85c66ab 100644 (file)
@@ -44,13 +44,14 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
 
     if (
       requestPayload?.hashId === undefined &&
-      (requestPayload?.hashIds as string[])?.includes(this.chargingStation.hashId) === false
+      (requestPayload?.hashIds as string[])?.includes(this.chargingStation.stationInfo.hashId) ===
+        false
     ) {
       return;
     }
     if (
       requestPayload?.hashIds === undefined &&
-      requestPayload?.hashId !== this.chargingStation.hashId
+      requestPayload?.hashId !== this.chargingStation.stationInfo.hashId
     ) {
       return;
     }
@@ -66,12 +67,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
       commandResponse = await this.commandHandler(command, requestPayload);
       if (commandResponse === undefined) {
         responsePayload = {
-          hashId: this.chargingStation.hashId,
+          hashId: this.chargingStation.stationInfo.hashId,
           status: ResponseStatus.SUCCESS,
         };
       } else {
         responsePayload = {
-          hashId: this.chargingStation.hashId,
+          hashId: this.chargingStation.stationInfo.hashId,
           status: this.commandResponseToResponseStatus(commandResponse),
         };
       }
@@ -81,7 +82,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
         error
       );
       responsePayload = {
-        hashId: this.chargingStation.hashId,
+        hashId: this.chargingStation.stationInfo.hashId,
         status: ResponseStatus.FAILURE,
         command,
         requestPayload,
index 9a88d17266dfdc4dceeab44930e5732e2109ad75..11eea6e66d28b79ccf3fab437725b50bd2d696da 100644 (file)
@@ -51,7 +51,6 @@ export class MessageChannelUtils {
     chargingStation: ChargingStation
   ): ChargingStationData {
     return {
-      hashId: chargingStation.hashId,
       stationInfo: chargingStation.stationInfo,
       stopped: chargingStation.stopped,
       bootNotificationResponse: chargingStation.bootNotificationResponse,
index 4f9697a67a0be01889e5ebf9a3ab080f020aa872..192e5771c0152ecf83126778b2a9eac38db69a3b 100644 (file)
@@ -11,6 +11,7 @@ export default interface ChargingStationInfo
     | 'chargePointSerialNumberPrefix'
     | 'meterSerialNumberPrefix'
   > {
+  hashId: string;
   infoHash?: string;
   chargingStationId?: string;
   chargeBoxSerialNumber?: string;
index d3ba12c7128bd93924a795e052482b49144bbab1..8a8fd381d3080f16a6cb1e434a0d5413eb57586e 100644 (file)
@@ -16,7 +16,6 @@ export interface ChargingStationWorkerData extends WorkerData {
 }
 
 export interface ChargingStationData extends WorkerData {
-  hashId: string;
   stationInfo: ChargingStationInfo;
   stopped: boolean;
   bootNotificationResponse: BootNotificationResponse;
index 2fb7822e7986ebef3d8fcb52dd3721a5b29c77a1..d716d2dfde853db8123c57792f3ad5abd0e69f46 100644 (file)
@@ -32,8 +32,8 @@ import type { ConnectorStatus } from '@/types/ChargingStationType';
 const props = defineProps<{
   hashId: string;
   connector: ConnectorStatus;
-  transactionId?: number;
   connectorId: number;
+  transactionId?: number;
   idTag?: string;
 }>();
 
index ea8fd1da86569ad5870dabce006ec0c7dfbf49eb..f4539469ccc97b795e0b7386ed6e40792aefa7d6 100644 (file)
@@ -42,15 +42,15 @@ const props = defineProps<{
 //   idTag: '',
 // });
 
-function getHashId(): string {
-  return props.chargingStation.hashId;
-}
 function getConnectors(): ConnectorStatus[] {
   return props.chargingStation.connectors?.slice(1);
 }
 function getInfo(): ChargingStationInfo {
   return props.chargingStation.stationInfo;
 }
+function getHashId(): string {
+  return getInfo().hashId;
+}
 function getId(): string {
   return Utils.ifUndefined<string>(getInfo().chargingStationId, 'Ø');
 }
index 04f38aa16901733c69522f1c4cae30f1b1a307c5..ccd7db14e4fc4862e7765e1822daf27c978c0ea4 100644 (file)
@@ -17,7 +17,7 @@
     <tbody id="cs-table__body">
       <CSData
         v-for="chargingStation in chargingStations"
-        :key="chargingStation.hashId"
+        :key="chargingStation.stationInfo.hashId"
         :charging-station="chargingStation"
         :idTag="props.idTag"
       />
index 4d4a7a4d3b152b0ee94029a68862952648847fe5..8d6f968537eeefbf4d2ade590aca799db811d1bb 100644 (file)
@@ -1,7 +1,6 @@
 import type { JsonObject } from './JsonType';
 
 export type ChargingStationData = {
-  hashId: string;
   stationInfo: ChargingStationInfo;
   stopped: boolean;
   bootNotificationResponse: BootNotificationResponse;
@@ -9,6 +8,7 @@ export type ChargingStationData = {
 };
 
 export type ChargingStationInfo = {
+  hashId: string;
   chargingStationId?: string;
   chargePointModel: string;
   chargePointVendor: string;
index 00feba445ff939cbc933eac0daf1a12fc0cfb4c4..3b90b6fb78cf301017ea746aa2fb47b7298b68e9 100644 (file)
@@ -1,3 +1,5 @@
+import { threadId } from 'worker_threads';
+
 import chalk from 'chalk';
 
 export class WorkerUtils {
@@ -7,7 +9,7 @@ export class WorkerUtils {
 
   public static defaultExitHandler = (code: number): void => {
     if (code !== 0) {
-      console.error(chalk.red(`Worker stopped with exit code ${code}`));
+      console.error(chalk.red(`Worker ${threadId} stopped with exit code ${code}`));
     }
   };
 }