X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationWorkerBroadcastChannel.ts;h=49ce0811d534be1e339c466a2b839132749235e3;hb=728e01f09f2b43946aab50eb2ed9673bf2d2daa3;hp=ea262a4c46bff108c6d204bafdcaf541c2d2f0f1;hpb=12052fe9e1facd942e01ec3926c4cfaf88c1cb62;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index ea262a4c..49ce0811 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -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, - 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 | void; -export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel { +export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel { private readonly commandHandlers: Map; private readonly chargingStation: ChargingStation; @@ -92,12 +85,17 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca [ BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR, (requestPayload?: BroadcastChannelRequestPayload) => - this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds), + this.chargingStation.startAutomaticTransactionGenerator(requestPayload?.connectorIds), ], [ BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR, (requestPayload?: BroadcastChannelRequestPayload) => - this.chargingStation.stopAutomaticTransactionGenerator(requestPayload.connectorIds), + this.chargingStation.stopAutomaticTransactionGenerator(requestPayload?.connectorIds), + ], + [ + BroadcastChannelProcedureName.SET_SUPERVISION_URL, + (requestPayload?: BroadcastChannelRequestPayload) => + this.chargingStation.setSupervisionUrl(requestPayload?.url as string), ], [ BroadcastChannelProcedureName.START_TRANSACTION, @@ -113,14 +111,18 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca this.chargingStation.ocppRequestService.requestHandler< StopTransactionRequest, StartTransactionResponse - >(this.chargingStation, RequestCommand.STOP_TRANSACTION, { - meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( - requestPayload.transactionId, - true - ), - ...requestPayload, - requestParams, - }), + >( + this.chargingStation, + RequestCommand.STOP_TRANSACTION, + { + meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( + requestPayload.transactionId, + true + ), + ...requestPayload, + }, + requestParams + ), ], [ BroadcastChannelProcedureName.AUTHORIZE, @@ -184,21 +186,26 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca return this.chargingStation.ocppRequestService.requestHandler< MeterValuesRequest, MeterValuesResponse - >(this.chargingStation, RequestCommand.METER_VALUES, { - meterValue: [ - // FIXME: Implement OCPP version agnostic helpers - OCPP16ServiceUtils.buildMeterValue( - this.chargingStation, - requestPayload.connectorId, - this.chargingStation.getConnectorStatus(requestPayload.connectorId)?.transactionId, - configuredMeterValueSampleInterval - ? Utils.convertToInt(configuredMeterValueSampleInterval.value) * 1000 - : Constants.DEFAULT_METER_VALUES_INTERVAL - ), - ], - ...requestPayload, - requestParams, - }); + >( + this.chargingStation, + RequestCommand.METER_VALUES, + { + meterValue: [ + // FIXME: Implement OCPP version agnostic helpers + OCPP16ServiceUtils.buildMeterValue( + this.chargingStation, + requestPayload.connectorId, + this.chargingStation.getConnectorStatus(requestPayload.connectorId) + ?.transactionId, + configuredMeterValueSampleInterval + ? Utils.convertToInt(configuredMeterValueSampleInterval.value) * 1000 + : Constants.DEFAULT_METER_VALUES_INTERVAL + ), + ], + ...requestPayload, + }, + requestParams + ); }, ], [