refactor(simulator): align casing on enums between key and value
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 27 Feb 2023 11:15:20 +0000 (12:15 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 27 Feb 2023 11:15:20 +0000 (12:15 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
14 files changed:
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ChargingStationWorker.ts
src/charging-station/MessageChannelUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/types/ChargingStationWorker.ts
src/types/ocpp/1.6/ChargePointStatus.ts
src/types/ocpp/2.0/Common.ts
src/utils/Configuration.ts
src/worker/WorkerFactory.ts
src/worker/WorkerSet.ts
src/worker/WorkerTypes.ts

index 5f20e74b6ca320224e374bc4cbfe63e55dd70dec..6be5d275682b3e5bdf5ead54916334d94825ebee 100644 (file)
@@ -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:
index f57aebed788c3135aa08bae6ebc392c3640bd63e..5b260cb6e7d8208a14ea7dea6ffbf72352b96313 100644 (file)
@@ -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;
index 22e712d03432a0e4c1a4557f0dbde07db42f54cd..957aee902adc42e3809aa9766dd64bcd4ab43712 100644 (file)
@@ -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(
index b4325dbe4c1db192035652089621ffba1eef42c3..c720b21980ae6ad2cf9165054a949c122c27061b 100644 (file)
@@ -29,7 +29,7 @@ if (ChargingStationUtils.workerPoolInUse()) {
  */
 function addMessageListener(): void {
   parentPort?.on('message', (message: WorkerMessage<ChargingStationWorkerData>) => {
-    if (message.id === WorkerMessageEvents.START_WORKER_ELEMENT) {
+    if (message.id === WorkerMessageEvents.startWorkerElement) {
       startChargingStation(message.data);
     }
   });
index 1bc26d622289bf63454e809836b3f45f00bce834..446ecfbbdef0b0ee2371e57b8a0668459e165024 100644 (file)
@@ -15,7 +15,7 @@ export class MessageChannelUtils {
     chargingStation: ChargingStation
   ): ChargingStationWorkerMessage<ChargingStationData> {
     return {
-      id: ChargingStationWorkerMessageEvents.STARTED,
+      id: ChargingStationWorkerMessageEvents.started,
       data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
     };
   }
@@ -24,7 +24,7 @@ export class MessageChannelUtils {
     chargingStation: ChargingStation
   ): ChargingStationWorkerMessage<ChargingStationData> {
     return {
-      id: ChargingStationWorkerMessageEvents.STOPPED,
+      id: ChargingStationWorkerMessageEvents.stopped,
       data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
     };
   }
@@ -33,7 +33,7 @@ export class MessageChannelUtils {
     chargingStation: ChargingStation
   ): ChargingStationWorkerMessage<ChargingStationData> {
     return {
-      id: ChargingStationWorkerMessageEvents.UPDATED,
+      id: ChargingStationWorkerMessageEvents.updated,
       data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
     };
   }
@@ -42,7 +42,7 @@ export class MessageChannelUtils {
     statistics: Statistics
   ): ChargingStationWorkerMessage<Statistics> {
     return {
-      id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS,
+      id: ChargingStationWorkerMessageEvents.performanceStatistics,
       data: statistics,
     };
   }
index 1179d425f1e0dd3ff4c92ed6e9c72ed321e0ed98..e2d5886bc799001d36837bef11bff647a2850297 100644 (file)
@@ -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<GenericResponse> {
     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 (
index df8a02e8ca2b9861a904a328236db4bbf4ea1757..2c92b6bd4b19c2e1444922444f1579ff830b5a48 100644 (file)
@@ -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<void> {
     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--;
index d53152dc00dd4c2cf56f0d23064d35548468d9cc..7578b217270a8e7f6342ef68c7bc90638d9efcd9 100644 (file)
@@ -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 = {
index 272d757e958fec19b8f9610ec1b95e031baa6a19..d7a197ae0f4c32307b296986bc0e140920f1aeb7 100644 (file)
@@ -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',
 }
index ba908562c87bb70b013bbb94e9436f0db133fd55..12dfd6a765eebfb651263abd03d59acd97b73e55 100644 (file)
@@ -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;
index 37569086ac69ba34e15340117c3c5bc4d3dae1ab..36b4e362a565f3f998df78cd01d73da56e0a5b96 100644 (file)
@@ -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,
index ff13b80fec190e3ebd4050d38f76266c64b74bb2..a5b401a3698417887c77426f843d0cae48bd61f0 100644 (file)
@@ -33,17 +33,17 @@ export class WorkerFactory {
       (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler);
     let workerImplementation: WorkerAbstract<T> | 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 =
index b8507d53fe96d24898d418ae1006bfca7cdfddbf..eaa19ac8f384ed5ce591362696e13bfdf765ab5a 100644 (file)
@@ -52,7 +52,7 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
       await this.startWorker();
     }
     this.getLastWorker().postMessage({
-      id: WorkerMessageEvents.START_WORKER_ELEMENT,
+      id: WorkerMessageEvents.startWorkerElement,
       data: elementData,
     });
     this.getLastWorkerSetElement().numberOfWorkerElements++;
index f79be0b28d866861d826b9cdafe3596561ecd9fe..1b7cbb300cf95a7ac5c9ba22bc4e8ac4a622afe6 100644 (file)
@@ -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<T> = (this: T, message: unknown) => void;
@@ -33,5 +33,5 @@ export type WorkerMessage<T extends WorkerData> = {
 };
 
 export enum WorkerMessageEvents {
-  START_WORKER_ELEMENT = 'startWorkerElement',
+  startWorkerElement = 'startWorkerElement',
 }