refactor(simulator): constify and factor out empty data structure
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
index dca2e06047699f69190fd7fc2c4ba00f43c55887..4185215aae0d25ceccf9618bb289712d46d96ed2 100644 (file)
@@ -1,33 +1,29 @@
 // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
-import { AsyncResource } from 'async_hooks';
+import { AsyncResource } from 'node:async_hooks';
 
-import type ChargingStation from './ChargingStation';
-import { ChargingStationUtils } from './ChargingStationUtils';
-import BaseError from '../exception/BaseError';
-import PerformanceStatistics from '../performance/PerformanceStatistics';
-import {
-  type AutomaticTransactionGeneratorConfiguration,
-  IdTagDistribution,
-  type Status,
-} from '../types/AutomaticTransactionGenerator';
-import { RequestCommand } from '../types/ocpp/Requests';
+import { type ChargingStation, ChargingStationUtils } from './internal';
+import { BaseError } from '../exception';
+// import { PerformanceStatistics } from '../performance';
+import { PerformanceStatistics } from '../performance/PerformanceStatistics';
 import {
   AuthorizationStatus,
   type AuthorizeRequest,
   type AuthorizeResponse,
+  type AutomaticTransactionGeneratorConfiguration,
+  IdTagDistribution,
+  RequestCommand,
   type StartTransactionRequest,
   type StartTransactionResponse,
+  type Status,
   StopTransactionReason,
   type StopTransactionResponse,
-} from '../types/ocpp/Transaction';
-import Constants from '../utils/Constants';
-import logger from '../utils/Logger';
-import Utils from '../utils/Utils';
+} from '../types';
+import { Constants, Utils, logger } from '../utils';
 
 const moduleName = 'AutomaticTransactionGenerator';
 
-export default class AutomaticTransactionGenerator extends AsyncResource {
+export class AutomaticTransactionGenerator extends AsyncResource {
   private static readonly instances: Map<string, AutomaticTransactionGenerator> = new Map<
     string,
     AutomaticTransactionGenerator
@@ -105,9 +101,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource {
         ) => Promise<void>,
         this,
         connectorId
-      ).catch(() => {
-        /* This is intentional */
-      });
+      ).catch(Constants.EMPTY_FUNCTION);
     } else if (this.connectorsStatus.get(connectorId)?.start === true) {
       logger.warn(`${this.logPrefix(connectorId)} is already started on connector`);
     }