X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Fbroadcast-channel%2FChargingStationWorkerBroadcastChannel.ts;h=a8d9b045abde5b93728ab16548a3a4e91fec8511;hb=7375968c99fc22707e16e5e7923ca130c824ce5b;hp=84d6961e56cbde3acc4b1e5302e9d0dbed647c6b;hpb=a37fc6dc8267e22b2b2d35773525980b81f014e8;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts index 84d6961e..a8d9b045 100644 --- a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts @@ -1,3 +1,5 @@ +import { secondsToMilliseconds } from 'date-fns'; + import { WorkerBroadcastChannel } from './WorkerBroadcastChannel'; import { BaseError, type OCPPError } from '../../exception'; import { @@ -15,6 +17,7 @@ import { DataTransferStatus, type DiagnosticsStatusNotificationRequest, type DiagnosticsStatusNotificationResponse, + type EmptyObject, type FirmwareStatusNotificationRequest, type FirmwareStatusNotificationResponse, type HeartbeatRequest, @@ -36,17 +39,17 @@ import { } from '../../types'; import { Constants, convertToInt, isEmptyObject, isNullOrUndefined, logger } from '../../utils'; import type { ChargingStation } from '../ChargingStation'; -import { ChargingStationConfigurationUtils } from '../ChargingStationConfigurationUtils'; +import { getConfigurationKey } from '../ConfigurationKeyUtils'; import { OCPP16ServiceUtils } from '../ocpp'; const moduleName = 'ChargingStationWorkerBroadcastChannel'; type CommandResponse = + | EmptyObject | StartTransactionResponse | StopTransactionResponse | AuthorizeResponse | BootNotificationResponse - | StatusNotificationResponse | HeartbeatResponse | DataTransferResponse; @@ -173,11 +176,10 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne [ BroadcastChannelProcedureName.METER_VALUES, async (requestPayload?: BroadcastChannelRequestPayload) => { - const configuredMeterValueSampleInterval = - ChargingStationConfigurationUtils.getConfigurationKey( - chargingStation, - StandardParametersKey.MeterValueSampleInterval, - ); + const configuredMeterValueSampleInterval = getConfigurationKey( + chargingStation, + StandardParametersKey.MeterValueSampleInterval, + ); return this.chargingStation.ocppRequestService.requestHandler< MeterValuesRequest, MeterValuesResponse @@ -192,8 +194,8 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne requestPayload!.connectorId!, this.chargingStation.getConnectorStatus(requestPayload!.connectorId!)! .transactionId!, - configuredMeterValueSampleInterval - ? convertToInt(configuredMeterValueSampleInterval.value) * 1000 + configuredMeterValueSampleInterval !== undefined + ? secondsToMilliseconds(convertToInt(configuredMeterValueSampleInterval.value)) : Constants.DEFAULT_METER_VALUES_INTERVAL, ), ], @@ -253,12 +255,12 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne } const [uuid, command, requestPayload] = validatedMessageEvent.data as BroadcastChannelRequest; if ( - !isNullOrUndefined(requestPayload?.hashIds) && - requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false + !isNullOrUndefined(requestPayload.hashIds) && + requestPayload.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false ) { return; } - if (!isNullOrUndefined(requestPayload?.hashId)) { + if (!isNullOrUndefined(requestPayload.hashId)) { logger.error( `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead`, ); @@ -291,8 +293,8 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne command, requestPayload, commandResponse: commandResponse as CommandResponse, - errorMessage: (error as Error).message, - errorStack: (error as Error).stack, + errorMessage: (error as OCPPError).message, + errorStack: (error as OCPPError).stack, errorDetails: (error as OCPPError).details, }; } finally { @@ -315,7 +317,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne this.cleanRequestPayload(command, requestPayload); return this.commandHandlers.get(command)!(requestPayload); } - throw new BaseError(`Unknown worker broadcast channel command: ${command}`); + throw new BaseError(`Unknown worker broadcast channel command: '${command}'`); } private cleanRequestPayload(