From 721646e902fa12d165d4a1da06fb963fb30dc9f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 27 Feb 2023 12:15:20 +0100 Subject: [PATCH] refactor(simulator): align casing on enums between key and value MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 8 +++--- src/charging-station/ChargingStation.ts | 6 ++--- src/charging-station/ChargingStationUtils.ts | 4 +-- src/charging-station/ChargingStationWorker.ts | 2 +- src/charging-station/MessageChannelUtils.ts | 8 +++--- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 26 +++++++++---------- .../ocpp/1.6/OCPP16ResponseService.ts | 22 ++++++++-------- src/types/ChargingStationWorker.ts | 8 +++--- src/types/ocpp/1.6/ChargePointStatus.ts | 20 +++++++------- src/types/ocpp/2.0/Common.ts | 10 +++---- src/utils/Configuration.ts | 2 +- src/worker/WorkerFactory.ts | 6 ++--- src/worker/WorkerSet.ts | 2 +- src/worker/WorkerTypes.ts | 8 +++--- 14 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 5f20e74b..6be5d275 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -170,16 +170,16 @@ export class Bootstrap { // ); try { switch (msg.id) { - case ChargingStationWorkerMessageEvents.STARTED: + case ChargingStationWorkerMessageEvents.started: this.workerEventStarted(msg.data as ChargingStationData); break; - case ChargingStationWorkerMessageEvents.STOPPED: + case ChargingStationWorkerMessageEvents.stopped: this.workerEventStopped(msg.data as ChargingStationData); break; - case ChargingStationWorkerMessageEvents.UPDATED: + case ChargingStationWorkerMessageEvents.updated: this.workerEventUpdated(msg.data as ChargingStationData); break; - case ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS: + case ChargingStationWorkerMessageEvents.performanceStatistics: this.workerEventPerformanceStatistics(msg.data as Statistics); break; default: diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index f57aebed..5b260cb6 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1814,7 +1814,7 @@ export class ChargingStation { (this.isChargingStationAvailable() === false || this.isConnectorAvailable(connectorId) === false) ) { - connectorStatus = ConnectorStatusEnum.UNAVAILABLE; + connectorStatus = ConnectorStatusEnum.Unavailable; } else if ( !this.getConnectorStatus(connectorId)?.status && this.getConnectorStatus(connectorId)?.bootStatus @@ -1826,7 +1826,7 @@ export class ChargingStation { connectorStatus = this.getConnectorStatus(connectorId)?.status; } else { // Set default status - connectorStatus = ConnectorStatusEnum.AVAILABLE; + connectorStatus = ConnectorStatusEnum.Available; } await this.ocppRequestService.requestHandler< StatusNotificationRequest, @@ -1879,7 +1879,7 @@ export class ChargingStation { OCPPServiceUtils.buildStatusNotificationRequest( this, connectorId, - ConnectorStatusEnum.UNAVAILABLE + ConnectorStatusEnum.Unavailable ) ); this.getConnectorStatus(connectorId).status = undefined; diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 22e712d0..957aee90 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -194,13 +194,13 @@ export class ChargingStationUtils { } public static workerPoolInUse(): boolean { - return [WorkerProcessType.DYNAMIC_POOL, WorkerProcessType.STATIC_POOL].includes( + return [WorkerProcessType.dynamicPool, WorkerProcessType.staticPool].includes( Configuration.getWorker().processType ); } public static workerDynamicPoolInUse(): boolean { - return Configuration.getWorker().processType === WorkerProcessType.DYNAMIC_POOL; + return Configuration.getWorker().processType === WorkerProcessType.dynamicPool; } public static warnDeprecatedTemplateKey( diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index b4325dbe..c720b219 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -29,7 +29,7 @@ if (ChargingStationUtils.workerPoolInUse()) { */ function addMessageListener(): void { parentPort?.on('message', (message: WorkerMessage) => { - if (message.id === WorkerMessageEvents.START_WORKER_ELEMENT) { + if (message.id === WorkerMessageEvents.startWorkerElement) { startChargingStation(message.data); } }); diff --git a/src/charging-station/MessageChannelUtils.ts b/src/charging-station/MessageChannelUtils.ts index 1bc26d62..446ecfbb 100644 --- a/src/charging-station/MessageChannelUtils.ts +++ b/src/charging-station/MessageChannelUtils.ts @@ -15,7 +15,7 @@ export class MessageChannelUtils { chargingStation: ChargingStation ): ChargingStationWorkerMessage { return { - id: ChargingStationWorkerMessageEvents.STARTED, + id: ChargingStationWorkerMessageEvents.started, data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), }; } @@ -24,7 +24,7 @@ export class MessageChannelUtils { chargingStation: ChargingStation ): ChargingStationWorkerMessage { return { - id: ChargingStationWorkerMessageEvents.STOPPED, + id: ChargingStationWorkerMessageEvents.stopped, data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), }; } @@ -33,7 +33,7 @@ export class MessageChannelUtils { chargingStation: ChargingStation ): ChargingStationWorkerMessage { return { - id: ChargingStationWorkerMessageEvents.UPDATED, + id: ChargingStationWorkerMessageEvents.updated, data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), }; } @@ -42,7 +42,7 @@ export class MessageChannelUtils { statistics: Statistics ): ChargingStationWorkerMessage { return { - id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS, + id: ChargingStationWorkerMessageEvents.performanceStatistics, data: statistics, }; } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 1179d425..e2d5886b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -401,10 +401,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - status: OCPP16ChargePointStatus.AVAILABLE, + status: OCPP16ChargePointStatus.Available, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); - chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; + chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.Available; return OCPPConstants.OCPP_RESPONSE_UNLOCKED; } @@ -664,8 +664,8 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } const chargePointStatus: OCPP16ChargePointStatus = commandPayload.type === OCPP16AvailabilityType.OPERATIVE - ? OCPP16ChargePointStatus.AVAILABLE - : OCPP16ChargePointStatus.UNAVAILABLE; + ? OCPP16ChargePointStatus.Available + : OCPP16ChargePointStatus.Unavailable; if (connectorId === 0) { let response: ChangeAvailabilityResponse = OCPPConstants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED; for (const id of chargingStation.connectors.keys()) { @@ -725,11 +725,11 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId: transactionConnectorId, - status: OCPP16ChargePointStatus.PREPARING, + status: OCPP16ChargePointStatus.Preparing, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId); - connectorStatus.status = OCPP16ChargePointStatus.PREPARING; + connectorStatus.status = OCPP16ChargePointStatus.Preparing; if (chargingStation.isChargingStationAvailable() === true) { // Check if authorized if (chargingStation.getAuthorizeRemoteTxRequests() === true) { @@ -861,17 +861,17 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { idTag: string ): Promise { if ( - chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.AVAILABLE + chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Available ) { await chargingStation.ocppRequestService.requestHandler< OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - status: OCPP16ChargePointStatus.AVAILABLE, + status: OCPP16ChargePointStatus.Available, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); - chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; + chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.Available; } logger.warn( `${chargingStation.logPrefix()} Remote starting transaction REJECTED on connector Id ${connectorId.toString()}, idTag '${idTag}', availability '${ @@ -920,10 +920,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - status: OCPP16ChargePointStatus.FINISHING, + status: OCPP16ChargePointStatus.Finishing, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); - chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.FINISHING; + chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.Finishing; const stopResponse = await chargingStation.stopTransactionOnConnector( connectorId, OCPP16StopTransactionReason.REMOTE @@ -1000,11 +1000,11 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - status: OCPP16ChargePointStatus.UNAVAILABLE, + status: OCPP16ChargePointStatus.Unavailable, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); chargingStation.getConnectorStatus(connectorId).status = - OCPP16ChargePointStatus.UNAVAILABLE; + OCPP16ChargePointStatus.Unavailable; } } if ( diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index df8a02e8..2c92b6bd 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -506,8 +506,8 @@ export class OCPP16ResponseService extends OCPPResponseService { } if ( chargingStation.getConnectorStatus(connectorId)?.status !== - OCPP16ChargePointStatus.AVAILABLE && - chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.PREPARING + OCPP16ChargePointStatus.Available && + chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Preparing ) { logger.error( `${chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with status ${ @@ -552,10 +552,10 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - status: OCPP16ChargePointStatus.CHARGING, + status: OCPP16ChargePointStatus.Charging, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); - chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.CHARGING; + chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.Charging; logger.info( `${chargingStation.logPrefix()} Transaction ${payload.transactionId.toString()} STARTED on ${ chargingStation.stationInfo.chargingStationId @@ -591,17 +591,17 @@ export class OCPP16ResponseService extends OCPPResponseService { ): Promise { chargingStation.resetConnectorStatus(connectorId); if ( - chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.AVAILABLE + chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Available ) { await chargingStation.ocppRequestService.requestHandler< OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - status: OCPP16ChargePointStatus.AVAILABLE, + status: OCPP16ChargePointStatus.Available, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); - chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; + chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.Available; } } @@ -645,22 +645,22 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16StatusNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId: transactionConnectorId, - status: OCPP16ChargePointStatus.UNAVAILABLE, + status: OCPP16ChargePointStatus.Unavailable, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); chargingStation.getConnectorStatus(transactionConnectorId).status = - OCPP16ChargePointStatus.UNAVAILABLE; + OCPP16ChargePointStatus.Unavailable; } else { await chargingStation.ocppRequestService.requestHandler< OCPP16BootNotificationRequest, OCPP16BootNotificationResponse >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId: transactionConnectorId, - status: OCPP16ChargePointStatus.AVAILABLE, + status: OCPP16ChargePointStatus.Available, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); chargingStation.getConnectorStatus(transactionConnectorId).status = - OCPP16ChargePointStatus.AVAILABLE; + OCPP16ChargePointStatus.Available; } if (chargingStation.stationInfo.powerSharedByConnectors) { chargingStation.powerDivider--; diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index d53152dc..7578b217 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -36,10 +36,10 @@ export interface ChargingStationData extends WorkerData { } enum ChargingStationMessageEvents { - STARTED = 'started', - STOPPED = 'stopped', - UPDATED = 'updated', - PERFORMANCE_STATISTICS = 'performanceStatistics', + started = 'started', + stopped = 'stopped', + updated = 'updated', + performanceStatistics = 'performanceStatistics', } export const ChargingStationWorkerMessageEvents = { diff --git a/src/types/ocpp/1.6/ChargePointStatus.ts b/src/types/ocpp/1.6/ChargePointStatus.ts index 272d757e..d7a197ae 100644 --- a/src/types/ocpp/1.6/ChargePointStatus.ts +++ b/src/types/ocpp/1.6/ChargePointStatus.ts @@ -1,12 +1,12 @@ export enum OCPP16ChargePointStatus { - AVAILABLE = 'Available', - PREPARING = 'Preparing', - CHARGING = 'Charging', - OCCUPIED = 'Occupied', - SUSPENDED_EVSE = 'SuspendedEVSE', - SUSPENDED_EV = 'SuspendedEV', - FINISHING = 'Finishing', - RESERVED = 'Reserved', - UNAVAILABLE = 'Unavailable', - FAULTED = 'Faulted', + Available = 'Available', + Preparing = 'Preparing', + Charging = 'Charging', + Occupied = 'Occupied', + SuspendedEVSE = 'SuspendedEVSE', + SuspendedEV = 'SuspendedEV', + Finishing = 'Finishing', + Reserved = 'Reserved', + Unavailable = 'Unavailable', + Faulted = 'Faulted', } diff --git a/src/types/ocpp/2.0/Common.ts b/src/types/ocpp/2.0/Common.ts index ba908562..12dfd6a7 100644 --- a/src/types/ocpp/2.0/Common.ts +++ b/src/types/ocpp/2.0/Common.ts @@ -26,11 +26,11 @@ export enum BootReasonEnumType { } export enum OCPP20ConnectorStatusEnumType { - AVAILABLE = 'Available', - OCCUPIED = 'Occupied', - RESERVED = 'Reserved', - UNAVAILABLE = 'Unavailable', - FAULTED = 'Faulted', + Available = 'Available', + Occupied = 'Occupied', + Reserved = 'Reserved', + Unavailable = 'Unavailable', + Faulted = 'Faulted', } export type GenericStatusEnumType = GenericStatus; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 37569086..36b4e362 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -191,7 +191,7 @@ export class Configuration { let workerConfiguration: WorkerConfiguration = { processType: Utils.hasOwnProp(Configuration.getConfig(), 'workerProcess') ? Configuration.getConfig()?.workerProcess - : WorkerProcessType.WORKER_SET, + : WorkerProcessType.workerSet, startDelay: Utils.hasOwnProp(Configuration.getConfig(), 'workerStartDelay') ? Configuration.getConfig()?.workerStartDelay : WorkerConstants.DEFAULT_WORKER_START_DELAY, diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index ff13b80f..a5b401a3 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -33,17 +33,17 @@ export class WorkerFactory { (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler); let workerImplementation: WorkerAbstract | null = null; switch (workerProcessType) { - case WorkerProcessType.WORKER_SET: + case WorkerProcessType.workerSet: workerOptions.elementsPerWorker = workerOptions?.elementsPerWorker ?? WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER; workerImplementation = new WorkerSet(workerScript, workerOptions); break; - case WorkerProcessType.STATIC_POOL: + case WorkerProcessType.staticPool: workerOptions.poolMaxSize = workerOptions?.poolMaxSize ?? WorkerConstants.DEFAULT_POOL_MAX_SIZE; workerImplementation = new WorkerStaticPool(workerScript, workerOptions); break; - case WorkerProcessType.DYNAMIC_POOL: + case WorkerProcessType.dynamicPool: workerOptions.poolMinSize = workerOptions?.poolMinSize ?? WorkerConstants.DEFAULT_POOL_MIN_SIZE; workerOptions.poolMaxSize = diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index b8507d53..eaa19ac8 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -52,7 +52,7 @@ export class WorkerSet extends WorkerAbstract { await this.startWorker(); } this.getLastWorker().postMessage({ - id: WorkerMessageEvents.START_WORKER_ELEMENT, + id: WorkerMessageEvents.startWorkerElement, data: elementData, }); this.getLastWorkerSetElement().numberOfWorkerElements++; diff --git a/src/worker/WorkerTypes.ts b/src/worker/WorkerTypes.ts index f79be0b2..1b7cbb30 100644 --- a/src/worker/WorkerTypes.ts +++ b/src/worker/WorkerTypes.ts @@ -3,9 +3,9 @@ import type { Worker } from 'node:worker_threads'; import type { PoolOptions } from 'poolifier'; export enum WorkerProcessType { - WORKER_SET = 'workerSet', - DYNAMIC_POOL = 'dynamicPool', - STATIC_POOL = 'staticPool', + workerSet = 'workerSet', + dynamicPool = 'dynamicPool', + staticPool = 'staticPool', } export type MessageHandler = (this: T, message: unknown) => void; @@ -33,5 +33,5 @@ export type WorkerMessage = { }; export enum WorkerMessageEvents { - START_WORKER_ELEMENT = 'startWorkerElement', + startWorkerElement = 'startWorkerElement', } -- 2.34.1