X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fbroadcast-channel%2FChargingStationWorkerBroadcastChannel.ts;h=20f347fc48e2e920c342be8d920e5668206cc49a;hb=48c7e1d6db4b3cbf82d17e191b2255066c462a71;hp=d990c48e8cf698ca9e0c67d7ddbcb0b5967d3a50;hpb=a807045be19c1ed4996a44d8c2c8774e926dc6dc;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 d990c48e..20f347fc 100644 --- a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts @@ -37,13 +37,7 @@ import { type StopTransactionRequest, type StopTransactionResponse } from '../../types/index.js' -import { - Constants, - convertToInt, - isEmptyObject, - isNullOrUndefined, - logger -} from '../../utils/index.js' +import { Constants, convertToInt, isEmptyObject, logger } from '../../utils/index.js' import type { ChargingStation } from '../ChargingStation.js' import { getConfigurationKey } from '../ConfigurationKeyUtils.js' import { buildMeterValue } from '../ocpp/index.js' @@ -135,8 +129,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne RequestCommand.STOP_TRANSACTION, { meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - requestPayload!.transactionId!, + requestPayload?.transactionId, true ), ...requestPayload @@ -180,12 +173,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne await this.chargingStation.ocppRequestService.requestHandler< StatusNotificationRequest, StatusNotificationResponse - >( - this.chargingStation, - RequestCommand.STATUS_NOTIFICATION, - requestPayload, - requestParams - ) + >(this.chargingStation, RequestCommand.STATUS_NOTIFICATION, requestPayload, requestParams) ], [ BroadcastChannelProcedureName.HEARTBEAT, @@ -278,12 +266,13 @@ 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 + requestPayload.hashIds != null && + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + !requestPayload.hashIds.includes(this.chargingStation.stationInfo!.hashId) ) { return } - if (!isNullOrUndefined(requestPayload.hashId)) { + if (requestPayload.hashId != null) { logger.error( `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead` ) @@ -291,19 +280,19 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne } let responsePayload: BroadcastChannelResponsePayload | undefined // eslint-disable-next-line @typescript-eslint/no-invalid-void-type - let commandResponse: CommandResponse | void | undefined + let commandResponse: CommandResponse | void try { commandResponse = await this.commandHandler(command, requestPayload) - if (isNullOrUndefined(commandResponse) || isEmptyObject(commandResponse as CommandResponse)) { + if (commandResponse == null || isEmptyObject(commandResponse)) { responsePayload = { - hashId: this.chargingStation.stationInfo.hashId, + hashId: this.chargingStation.stationInfo?.hashId, status: ResponseStatus.SUCCESS } } else { responsePayload = this.commandResponseToResponsePayload( command, requestPayload, - commandResponse as CommandResponse + commandResponse ) } } catch (error) { @@ -312,7 +301,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne error ) responsePayload = { - hashId: this.chargingStation.stationInfo.hashId, + hashId: this.chargingStation.stationInfo?.hashId, status: ResponseStatus.FAILURE, command, requestPayload, @@ -339,7 +328,7 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne command: BroadcastChannelProcedureName, requestPayload: BroadcastChannelRequestPayload // eslint-disable-next-line @typescript-eslint/no-invalid-void-type - ): Promise { + ): Promise { if (this.commandHandlers.has(command)) { this.cleanRequestPayload(command, requestPayload) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -368,12 +357,12 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne const responseStatus = this.commandResponseToResponseStatus(command, commandResponse) if (responseStatus === ResponseStatus.SUCCESS) { return { - hashId: this.chargingStation.stationInfo.hashId, + hashId: this.chargingStation.stationInfo?.hashId, status: responseStatus } } return { - hashId: this.chargingStation.stationInfo.hashId, + hashId: this.chargingStation.stationInfo?.hashId, status: responseStatus, command, requestPayload, @@ -395,18 +384,18 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne | StartTransactionResponse | StopTransactionResponse | AuthorizeResponse - )?.idTagInfo?.status === AuthorizationStatus.ACCEPTED + ).idTagInfo?.status === AuthorizationStatus.ACCEPTED ) { return ResponseStatus.SUCCESS } return ResponseStatus.FAILURE case BroadcastChannelProcedureName.BOOT_NOTIFICATION: - if (commandResponse?.status === RegistrationStatusEnumType.ACCEPTED) { + if (commandResponse.status === RegistrationStatusEnumType.ACCEPTED) { return ResponseStatus.SUCCESS } return ResponseStatus.FAILURE case BroadcastChannelProcedureName.DATA_TRANSFER: - if (commandResponse?.status === DataTransferStatus.ACCEPTED) { + if (commandResponse.status === DataTransferStatus.ACCEPTED) { return ResponseStatus.SUCCESS } return ResponseStatus.FAILURE