build(deps): apply updates
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationWorkerBroadcastChannel.ts
index 28c23cf848198c746c51ca043770e2e14c38ac99..c03c4acb81db8aae2a01efee281e5558fbfb3a81 100644 (file)
@@ -1,52 +1,45 @@
-import type ChargingStation from './ChargingStation';
-import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
-import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils';
-import WorkerBroadcastChannel from './WorkerBroadcastChannel';
-import BaseError from '../exception/BaseError';
-import type OCPPError from '../exception/OCPPError';
-import { StandardParametersKey } from '../types/ocpp/Configuration';
 import {
-  type BootNotificationRequest,
-  type DataTransferRequest,
-  type DiagnosticsStatusNotificationRequest,
-  type FirmwareStatusNotificationRequest,
-  type HeartbeatRequest,
-  type MeterValuesRequest,
-  RequestCommand,
-  type RequestParams,
-  type StatusNotificationRequest,
-} from '../types/ocpp/Requests';
+  type ChargingStation,
+  ChargingStationConfigurationUtils,
+  WorkerBroadcastChannel,
+} from './internal';
+import { OCPP16ServiceUtils } from './ocpp';
+import { BaseError, type OCPPError } from '../exception';
 import {
+  AuthorizationStatus,
+  type AuthorizeRequest,
+  type AuthorizeResponse,
+  type BootNotificationRequest,
   type BootNotificationResponse,
+  BroadcastChannelProcedureName,
+  type BroadcastChannelRequest,
+  type BroadcastChannelRequestPayload,
+  type BroadcastChannelResponsePayload,
+  type DataTransferRequest,
   type DataTransferResponse,
   DataTransferStatus,
+  type DiagnosticsStatusNotificationRequest,
   type DiagnosticsStatusNotificationResponse,
+  type FirmwareStatusNotificationRequest,
   type FirmwareStatusNotificationResponse,
+  type HeartbeatRequest,
   type HeartbeatResponse,
+  type MessageEvent,
+  type MeterValuesRequest,
   type MeterValuesResponse,
   RegistrationStatusEnumType,
-  type StatusNotificationResponse,
-} from '../types/ocpp/Responses';
-import {
-  AuthorizationStatus,
-  type AuthorizeRequest,
-  type AuthorizeResponse,
+  RequestCommand,
+  type RequestParams,
+  ResponseStatus,
+  StandardParametersKey,
   type StartTransactionRequest,
   type StartTransactionResponse,
+  type StatusNotificationRequest,
+  type StatusNotificationResponse,
   type StopTransactionRequest,
   type StopTransactionResponse,
-} from '../types/ocpp/Transaction';
-import { ResponseStatus } from '../types/UIProtocol';
-import {
-  BroadcastChannelProcedureName,
-  type BroadcastChannelRequest,
-  type BroadcastChannelRequestPayload,
-  type BroadcastChannelResponsePayload,
-  type MessageEvent,
-} from '../types/WorkerBroadcastChannel';
-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 = 'ChargingStationWorkerBroadcastChannel';
 
@@ -66,7 +59,7 @@ type CommandHandler = (
   requestPayload?: BroadcastChannelRequestPayload
 ) => Promise<CommandResponse | void> | void;
 
-export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel {
+export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel {
   private readonly commandHandlers: Map<BroadcastChannelProcedureName, CommandHandler>;
   private readonly chargingStation: ChargingStation;
 
@@ -99,6 +92,11 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
         (requestPayload?: BroadcastChannelRequestPayload) =>
           this.chargingStation.stopAutomaticTransactionGenerator(requestPayload?.connectorIds),
       ],
+      [
+        BroadcastChannelProcedureName.SET_SUPERVISION_URL,
+        (requestPayload?: BroadcastChannelRequestPayload) =>
+          this.chargingStation.setSupervisionUrl(requestPayload?.url as string),
+      ],
       [
         BroadcastChannelProcedureName.START_TRANSACTION,
         async (requestPayload?: BroadcastChannelRequestPayload) =>
@@ -260,12 +258,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
     }
     const [uuid, command, requestPayload] = validatedMessageEvent.data as BroadcastChannelRequest;
     if (
-      requestPayload?.hashIds !== undefined &&
+      !Utils.isNullOrUndefined(requestPayload?.hashIds) &&
       requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false
     ) {
       return;
     }
-    if (requestPayload?.hashId !== undefined) {
+    if (!Utils.isNullOrUndefined(requestPayload?.hashId)) {
       logger.error(
         `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead`
       );
@@ -276,9 +274,8 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
     try {
       commandResponse = await this.commandHandler(command, requestPayload);
       if (
-        commandResponse === undefined ||
-        commandResponse === null ||
-        Utils.isEmptyObject(commandResponse)
+        Utils.isNullOrUndefined(commandResponse) ||
+        Utils.isEmptyObject(commandResponse as CommandResponse)
       ) {
         responsePayload = {
           hashId: this.chargingStation.stationInfo.hashId,
@@ -288,7 +285,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
         responsePayload = this.commandResponseToResponsePayload(
           command,
           requestPayload,
-          commandResponse
+          commandResponse as CommandResponse
         );
       }
     } catch (error) {