From 51c83d6f833f27f9990c17fc380ab5ee618894b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 30 Aug 2022 11:47:24 +0200 Subject: [PATCH] Move hashId to stationInfo MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 6 +++--- src/charging-station/Bootstrap.ts | 6 +++--- src/charging-station/ChargingStation.ts | 13 ++++++------- src/charging-station/ChargingStationUtils.ts | 2 +- .../ChargingStationWorkerBroadcastChannel.ts | 11 ++++++----- src/charging-station/MessageChannelUtils.ts | 1 - src/types/ChargingStationInfo.ts | 1 + src/types/ChargingStationWorker.ts | 1 - .../components/charging-stations/CSConnector.vue | 2 +- .../web/src/components/charging-stations/CSData.vue | 6 +++--- .../src/components/charging-stations/CSTable.vue | 2 +- src/ui/web/src/types/ChargingStationType.ts | 2 +- src/worker/WorkerUtils.ts | 4 +++- 13 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index a6408d2b..d9f0e249 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -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 { diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index d6bf3f37..27755836 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -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) => { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index a47bc681..66146be9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 ); diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 4f058b72..60e143fa 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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 { diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 6fc700d2..64332533 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -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, diff --git a/src/charging-station/MessageChannelUtils.ts b/src/charging-station/MessageChannelUtils.ts index 9a88d172..11eea6e6 100644 --- a/src/charging-station/MessageChannelUtils.ts +++ b/src/charging-station/MessageChannelUtils.ts @@ -51,7 +51,6 @@ export class MessageChannelUtils { chargingStation: ChargingStation ): ChargingStationData { return { - hashId: chargingStation.hashId, stationInfo: chargingStation.stationInfo, stopped: chargingStation.stopped, bootNotificationResponse: chargingStation.bootNotificationResponse, diff --git a/src/types/ChargingStationInfo.ts b/src/types/ChargingStationInfo.ts index 4f9697a6..192e5771 100644 --- a/src/types/ChargingStationInfo.ts +++ b/src/types/ChargingStationInfo.ts @@ -11,6 +11,7 @@ export default interface ChargingStationInfo | 'chargePointSerialNumberPrefix' | 'meterSerialNumberPrefix' > { + hashId: string; infoHash?: string; chargingStationId?: string; chargeBoxSerialNumber?: string; diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index d3ba12c7..8a8fd381 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -16,7 +16,6 @@ export interface ChargingStationWorkerData extends WorkerData { } export interface ChargingStationData extends WorkerData { - hashId: string; stationInfo: ChargingStationInfo; stopped: boolean; bootNotificationResponse: BootNotificationResponse; diff --git a/src/ui/web/src/components/charging-stations/CSConnector.vue b/src/ui/web/src/components/charging-stations/CSConnector.vue index 2fb7822e..d716d2df 100644 --- a/src/ui/web/src/components/charging-stations/CSConnector.vue +++ b/src/ui/web/src/components/charging-stations/CSConnector.vue @@ -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; }>(); diff --git a/src/ui/web/src/components/charging-stations/CSData.vue b/src/ui/web/src/components/charging-stations/CSData.vue index ea8fd1da..f4539469 100644 --- a/src/ui/web/src/components/charging-stations/CSData.vue +++ b/src/ui/web/src/components/charging-stations/CSData.vue @@ -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(getInfo().chargingStationId, 'Ø'); } diff --git a/src/ui/web/src/components/charging-stations/CSTable.vue b/src/ui/web/src/components/charging-stations/CSTable.vue index 04f38aa1..ccd7db14 100644 --- a/src/ui/web/src/components/charging-stations/CSTable.vue +++ b/src/ui/web/src/components/charging-stations/CSTable.vue @@ -17,7 +17,7 @@ diff --git a/src/ui/web/src/types/ChargingStationType.ts b/src/ui/web/src/types/ChargingStationType.ts index 4d4a7a4d..8d6f9685 100644 --- a/src/ui/web/src/types/ChargingStationType.ts +++ b/src/ui/web/src/types/ChargingStationType.ts @@ -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; diff --git a/src/worker/WorkerUtils.ts b/src/worker/WorkerUtils.ts index 00feba44..3b90b6fb 100644 --- a/src/worker/WorkerUtils.ts +++ b/src/worker/WorkerUtils.ts @@ -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}`)); } }; } -- 2.34.1