Ensure MeterValues command payload is properly formed
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPResponseService.ts
index 2fa0112c70c6d42fc29958da64007576824b6285..ffcb888fe422bf35bb24549205ff4dfbc3ba09f5 100644 (file)
@@ -1,31 +1,25 @@
-import type ChargingStation from '../ChargingStation';
 import { JsonType } from '../../types/JsonType';
 import { RequestCommand } from '../../types/ocpp/Requests';
+import type ChargingStation from '../ChargingStation';
 
 export default abstract class OCPPResponseService {
-  private static readonly instances: Map<string, OCPPResponseService> = new Map<
-    string,
-    OCPPResponseService
-  >();
-  protected readonly chargingStation: ChargingStation;
+  private static instance: OCPPResponseService | null = null;
 
-  protected constructor(chargingStation: ChargingStation) {
-    this.chargingStation = chargingStation;
+  protected constructor() {
+    // This is intentional
   }
 
-  public static getInstance<T extends OCPPResponseService>(
-    this: new (chargingStation: ChargingStation) => T,
-    chargingStation: ChargingStation
-  ): T {
-    if (!OCPPResponseService.instances.has(chargingStation.id)) {
-      OCPPResponseService.instances.set(chargingStation.id, new this(chargingStation));
+  public static getInstance<T extends OCPPResponseService>(this: new () => T): T {
+    if (!OCPPResponseService.instance) {
+      OCPPResponseService.instance = new this();
     }
-    return OCPPResponseService.instances.get(chargingStation.id) as T;
+    return OCPPResponseService.instance as T;
   }
 
-  public abstract handleResponse(
+  public abstract responseHandler(
+    chargingStation: ChargingStation,
     commandName: RequestCommand,
-    payload: JsonType | string,
+    payload: JsonType,
     requestPayload: JsonType
   ): Promise<void>;
 }