import { secondsToMilliseconds } from 'date-fns'
+import { isEmpty } from 'rambda'
-import { WorkerBroadcastChannel } from './WorkerBroadcastChannel.js'
import { BaseError, type OCPPError } from '../../exception/index.js'
import {
AuthorizationStatus,
type StopTransactionRequest,
type StopTransactionResponse
} from '../../types/index.js'
-import {
- Constants,
- convertToInt,
- isAsyncFunction,
- isEmptyObject,
- logger
-} from '../../utils/index.js'
+import { Constants, convertToInt, isAsyncFunction, logger } from '../../utils/index.js'
import type { ChargingStation } from '../ChargingStation.js'
import { getConfigurationKey } from '../ConfigurationKeyUtils.js'
import { buildMeterValue } from '../ocpp/index.js'
+import { WorkerBroadcastChannel } from './WorkerBroadcastChannel.js'
const moduleName = 'ChargingStationWorkerBroadcastChannel'
await this.chargingStation.stop()
}
],
+ [
+ BroadcastChannelProcedureName.DELETE_CHARGING_STATIONS,
+ async (requestPayload?: BroadcastChannelRequestPayload) => {
+ await this.chargingStation.delete(requestPayload?.deleteConfiguration as boolean)
+ }
+ ],
[
BroadcastChannelProcedureName.OPEN_CONNECTION,
() => {
[
BroadcastChannelProcedureName.BOOT_NOTIFICATION,
async (requestPayload?: BroadcastChannelRequestPayload) => {
- this.chargingStation.bootNotificationResponse =
- await this.chargingStation.ocppRequestService.requestHandler<
- BootNotificationRequest,
- BootNotificationResponse
- >(
- this.chargingStation,
- RequestCommand.BOOT_NOTIFICATION,
- {
- ...this.chargingStation.bootNotificationRequest,
- ...requestPayload
- },
- {
- skipBufferingOnError: true,
- throwError: true
- }
- )
- return this.chargingStation.bootNotificationResponse
+ return await this.chargingStation.ocppRequestService.requestHandler<
+ BootNotificationRequest,
+ BootNotificationResponse
+ >(
+ this.chargingStation,
+ RequestCommand.BOOT_NOTIFICATION,
+ {
+ ...this.chargingStation.bootNotificationRequest,
+ ...requestPayload
+ },
+ {
+ skipBufferingOnError: true,
+ throwError: true
+ }
+ )
}
],
[
return
}
let responsePayload: BroadcastChannelResponsePayload | undefined
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
- let commandResponse: CommandResponse | void
this.commandHandler(command, requestPayload)
.then(commandResponse => {
- if (commandResponse == null || isEmptyObject(commandResponse)) {
+ if (commandResponse == null || isEmpty(commandResponse)) {
responsePayload = {
hashId: this.chargingStation.stationInfo?.hashId,
status: ResponseStatus.SUCCESS
)
}
})
- .catch(error => {
+ .catch((error: unknown) => {
logger.error(
`${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: Handle request error:`,
error
status: ResponseStatus.FAILURE,
command,
requestPayload,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- commandResponse: commandResponse!,
errorMessage: (error as OCPPError).message,
errorStack: (error as OCPPError).stack,
errorDetails: (error as OCPPError).details
- }
+ } satisfies BroadcastChannelResponsePayload
})
.finally(() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return ResponseStatus.FAILURE
case BroadcastChannelProcedureName.STATUS_NOTIFICATION:
case BroadcastChannelProcedureName.METER_VALUES:
- if (isEmptyObject(commandResponse)) {
+ if (isEmpty(commandResponse)) {
return ResponseStatus.SUCCESS
}
return ResponseStatus.FAILURE