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'
RequestCommand.STOP_TRANSACTION,
{
meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- requestPayload!.transactionId!,
+ requestPayload?.transactionId,
true
),
...requestPayload
await this.chargingStation.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
- >(
- this.chargingStation,
- RequestCommand.STATUS_NOTIFICATION,
- requestPayload,
- requestParams
- )
+ >(this.chargingStation, RequestCommand.STATUS_NOTIFICATION, requestPayload, requestParams)
],
[
BroadcastChannelProcedureName.HEARTBEAT,
}
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`
)
}
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) {
error
)
responsePayload = {
- hashId: this.chargingStation.stationInfo.hashId,
+ hashId: this.chargingStation.stationInfo?.hashId,
status: ResponseStatus.FAILURE,
command,
requestPayload,
command: BroadcastChannelProcedureName,
requestPayload: BroadcastChannelRequestPayload
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
- ): Promise<void | CommandResponse> {
+ ): Promise<CommandResponse | void> {
if (this.commandHandlers.has(command)) {
this.cleanRequestPayload(command, requestPayload)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
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,
| 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