refactor: cleanup boot notification response assignation
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPIncomingRequestService.ts
index 7203569749e04d8ee88a238e4ac2f0ea754382da..8cfc8bc8375a52f3618e5faecbd4641f3c2b0d30 100644 (file)
@@ -1,8 +1,8 @@
+import { EventEmitter } from 'node:events'
+
 import _Ajv, { type ValidateFunction } from 'ajv'
 import _ajvFormats from 'ajv-formats'
 
-import { OCPPConstants } from './OCPPConstants.js'
-import { OCPPServiceUtils } from './OCPPServiceUtils.js'
 import { type ChargingStation, getIdTagsFile } from '../../charging-station/index.js'
 import { OCPPError } from '../../exception/index.js'
 import type {
@@ -13,6 +13,8 @@ import type {
   OCPPVersion
 } from '../../types/index.js'
 import { logger, setDefaultErrorParams } from '../../utils/index.js'
+import { OCPPConstants } from './OCPPConstants.js'
+import { OCPPServiceUtils } from './OCPPServiceUtils.js'
 type Ajv = _Ajv.default
 // eslint-disable-next-line @typescript-eslint/no-redeclare
 const Ajv = _Ajv.default
@@ -20,7 +22,7 @@ const ajvFormats = _ajvFormats.default
 
 const moduleName = 'OCPPIncomingRequestService'
 
-export abstract class OCPPIncomingRequestService {
+export abstract class OCPPIncomingRequestService extends EventEmitter {
   private static instance: OCPPIncomingRequestService | null = null
   private readonly version: OCPPVersion
   protected readonly ajv: Ajv
@@ -30,6 +32,7 @@ export abstract class OCPPIncomingRequestService {
   >
 
   protected constructor (version: OCPPVersion) {
+    super()
     this.version = version
     this.ajv = new Ajv({
       keywords: ['javaType'],
@@ -53,7 +56,7 @@ export abstract class OCPPIncomingRequestService {
     error: Error,
     params: HandleErrorParams<T> = { throwError: true, consoleOut: false }
   ): T | undefined {
-    setDefaultErrorParams(params)
+    params = setDefaultErrorParams(params)
     logger.error(
       `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
       error