// Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved.
-import type { JSONSchemaType } from 'ajv'
+import type { ValidateFunction } from 'ajv'
import { secondsToMilliseconds } from 'date-fns'
-import { OCPP16ServiceUtils } from './OCPP16ServiceUtils.js'
import {
- type ChargingStation,
addConfigurationKey,
+ type ChargingStation,
getConfigurationKey,
hasReservationExpired,
resetConnectorStatus
import { OCPPError } from '../../../exception/index.js'
import {
type ChangeConfigurationResponse,
+ ChargingStationEvents,
ErrorType,
type GenericResponse,
type GetConfigurationResponse,
type SetChargingProfileResponse,
type UnlockConnectorResponse
} from '../../../types/index.js'
-import { Constants, convertToInt, logger } from '../../../utils/index.js'
+import { Constants, convertToInt, isAsyncFunction, logger } from '../../../utils/index.js'
import { OCPPResponseService } from '../OCPPResponseService.js'
+import { OCPP16ServiceUtils } from './OCPP16ServiceUtils.js'
const moduleName = 'OCPP16ResponseService'
export class OCPP16ResponseService extends OCPPResponseService {
- public jsonIncomingRequestResponseSchemas: Map<
+ public incomingRequestResponsePayloadValidateFunctions: Map<
OCPP16IncomingRequestCommand,
- JSONSchemaType<JsonType>
+ ValidateFunction<JsonType>
>
+ protected payloadValidateFunctions: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
private readonly responseHandlers: Map<OCPP16RequestCommand, ResponseHandler>
- private readonly jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>
public constructor () {
// if (new.target.name === moduleName) {
OCPP16RequestCommand.BOOT_NOTIFICATION,
this.handleResponseBootNotification.bind(this) as ResponseHandler
],
- [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler],
[OCPP16RequestCommand.AUTHORIZE, this.handleResponseAuthorize.bind(this) as ResponseHandler],
[
OCPP16RequestCommand.START_TRANSACTION,
OCPP16RequestCommand.STATUS_NOTIFICATION,
this.emptyResponseHandler.bind(this) as ResponseHandler
],
- [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler],
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
this.emptyResponseHandler.bind(this) as ResponseHandler
],
- [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this) as ResponseHandler],
- [
- OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
- this.emptyResponseHandler.bind(this) as ResponseHandler
- ]
+ [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler],
+ [OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, this.emptyResponseHandler]
])
- this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>([
+ this.payloadValidateFunctions = new Map<OCPP16RequestCommand, ValidateFunction<JsonType>>([
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
- 'assets/json-schemas/ocpp/1.6/BootNotificationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
+ 'assets/json-schemas/ocpp/1.6/BootNotificationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.HEARTBEAT,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
- 'assets/json-schemas/ocpp/1.6/HeartbeatResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
+ 'assets/json-schemas/ocpp/1.6/HeartbeatResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.AUTHORIZE,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
- 'assets/json-schemas/ocpp/1.6/AuthorizeResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
+ 'assets/json-schemas/ocpp/1.6/AuthorizeResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.START_TRANSACTION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
- 'assets/json-schemas/ocpp/1.6/StartTransactionResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
+ 'assets/json-schemas/ocpp/1.6/StartTransactionResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.STOP_TRANSACTION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
- 'assets/json-schemas/ocpp/1.6/StopTransactionResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
+ 'assets/json-schemas/ocpp/1.6/StopTransactionResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
- 'assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
+ 'assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.METER_VALUES,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
- 'assets/json-schemas/ocpp/1.6/MeterValuesResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
+ 'assets/json-schemas/ocpp/1.6/MeterValuesResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
- 'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
+ 'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.DATA_TRANSFER,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
- 'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ 'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
- 'assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajv
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
+ 'assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
]
])
- this.jsonIncomingRequestResponseSchemas = new Map([
+ this.incomingRequestResponsePayloadValidateFunctions = new Map<
+ OCPP16IncomingRequestCommand,
+ ValidateFunction<JsonType>
+ >([
[
OCPP16IncomingRequestCommand.RESET,
- OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- 'assets/json-schemas/ocpp/1.6/ResetResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
+ 'assets/json-schemas/ocpp/1.6/ResetResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
- OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- 'assets/json-schemas/ocpp/1.6/ClearCacheResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
+ 'assets/json-schemas/ocpp/1.6/ClearCacheResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ChangeAvailabilityResponse>(
- 'assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ChangeAvailabilityResponse>(
+ 'assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
- OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorResponse>(
- 'assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorResponse>(
+ 'assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationResponse>(
- 'assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationResponse>(
+ 'assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationResponse>(
- 'assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationResponse>(
+ 'assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16GetCompositeScheduleResponse>(
- 'assets/json-schemas/ocpp/1.6/GetCompositeScheduleResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16GetCompositeScheduleResponse>(
+ 'assets/json-schemas/ocpp/1.6/GetCompositeScheduleResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
- OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileResponse>(
- 'assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileResponse>(
+ 'assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ClearChargingProfileResponse>(
- 'assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ClearChargingProfileResponse>(
+ 'assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
- OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- 'assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
+ 'assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
- OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- 'assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
+ 'assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
- OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsResponse>(
- 'assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsResponse>(
+ 'assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
- 'assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
+ 'assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
- 'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ 'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
- 'assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
+ 'assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.RESERVE_NOW,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ReserveNowResponse>(
- 'assets/json-schemas/ocpp/1.6/ReserveNowResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ReserveNowResponse>(
+ 'assets/json-schemas/ocpp/1.6/ReserveNowResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
],
[
OCPP16IncomingRequestCommand.CANCEL_RESERVATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- 'assets/json-schemas/ocpp/1.6/CancelReservationResponse.json',
- moduleName,
- 'constructor'
- )
+ this.ajvIncomingRequest
+ .compile(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
+ 'assets/json-schemas/ocpp/1.6/CancelReservationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
]
])
- this.validatePayload = this.validatePayload.bind(this) as (
- chargingStation: ChargingStation,
- commandName: OCPP16RequestCommand,
- payload: JsonType
- ) => boolean
+ this.validatePayload = this.validatePayload.bind(this)
}
public async responseHandler<ReqType extends JsonType, ResType extends JsonType>(
try {
this.validatePayload(chargingStation, commandName, payload)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- await this.responseHandlers.get(commandName)!(chargingStation, payload, requestPayload)
+ const responseHandler = this.responseHandlers.get(commandName)!
+ if (isAsyncFunction(responseHandler)) {
+ await responseHandler(chargingStation, payload, requestPayload)
+ } else {
+ (
+ responseHandler as (
+ chargingStation: ChargingStation,
+ payload: JsonType,
+ requestPayload?: JsonType
+ ) => void
+ )(chargingStation, payload, requestPayload)
+ }
} catch (error) {
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.responseHandler: Handle response error:`,
payload,
undefined,
2
- )} while the charging station is not registered on the central server.`,
+ )} while the charging station is not registered on the central server`,
commandName,
payload
)
commandName: OCPP16RequestCommand,
payload: JsonType
): boolean {
- if (this.jsonSchemas.has(commandName)) {
- return this.validateResponsePayload(
- chargingStation,
- commandName,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.jsonSchemas.get(commandName)!,
- payload
- )
+ if (this.payloadValidateFunctions.has(commandName)) {
+ return this.validateResponsePayload(chargingStation, commandName, payload)
}
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
+ `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema validation function found for command '${commandName}' PDU validation`
)
return false
}
chargingStation: ChargingStation,
payload: OCPP16BootNotificationResponse
): void {
- if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
- addConfigurationKey(
- chargingStation,
- OCPP16StandardParametersKey.HeartbeatInterval,
- payload.interval.toString(),
- {},
- { overwrite: true, save: true }
- )
- addConfigurationKey(
- chargingStation,
- OCPP16StandardParametersKey.HeartBeatInterval,
- payload.interval.toString(),
- { visible: false },
- { overwrite: true, save: true }
- )
- OCPP16ServiceUtils.startHeartbeatInterval(chargingStation, payload.interval)
- }
if (Object.values(RegistrationStatusEnumType).includes(payload.status)) {
+ chargingStation.bootNotificationResponse = payload
+ if (chargingStation.isRegistered()) {
+ chargingStation.emit(ChargingStationEvents.registered)
+ if (chargingStation.inAcceptedState()) {
+ addConfigurationKey(
+ chargingStation,
+ OCPP16StandardParametersKey.HeartbeatInterval,
+ payload.interval.toString(),
+ {},
+ { overwrite: true, save: true }
+ )
+ addConfigurationKey(
+ chargingStation,
+ OCPP16StandardParametersKey.HeartBeatInterval,
+ payload.interval.toString(),
+ { visible: false },
+ { overwrite: true, save: true }
+ )
+ chargingStation.emit(ChargingStationEvents.accepted)
+ }
+ } else if (chargingStation.inRejectedState()) {
+ chargingStation.emit(ChargingStationEvents.rejected)
+ }
const logMsg = `${chargingStation.logPrefix()} Charging station in '${
payload.status
}' state on the central server`
? logger.warn(logMsg)
: logger.info(logMsg)
} else {
+ delete chargingStation.bootNotificationResponse
logger.error(
`${chargingStation.logPrefix()} Charging station boot notification response received: %j with undefined registration status`,
payload
authorizeConnectorStatus.idTagAuthorized = false
delete authorizeConnectorStatus.authorizeIdTag
logger.debug(
- `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' rejected with status '${
- payload.idTagInfo.status
- }`
+ `${chargingStation.logPrefix()} idTag '${
+ requestPayload.idTag
+ }' rejected with status '${payload.idTagInfo.status}'`
)
}
} else {
connectorStatus?.status !== OCPP16ChargePointStatus.Preparing
) {
logger.error(
- `${chargingStation.logPrefix()} Trying to start a transaction on connector id ${connectorId} with status ${connectorStatus?.status}`
+ `${chargingStation.logPrefix()} Trying to start a transaction on connector id ${connectorId} with status ${
+ connectorStatus?.status
+ }`
)
return
}
logger.warn(
`${chargingStation.logPrefix()} Reserved transaction ${
payload.transactionId
- } started with a different idTag ${requestPayload.idTag} than the reservation one ${
- reservation.idTag
- }`
+ } started with a different idTag ${
+ requestPayload.idTag
+ } than the reservation one ${reservation.idTag}`
)
}
if (hasReservationExpired(reservation)) {
OCPP16ChargePointStatus.Charging
)
logger.info(
- `${chargingStation.logPrefix()} Transaction with id ${
- payload.transactionId
- } STARTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId} for idTag '${
- requestPayload.idTag
- }'`
+ `${chargingStation.logPrefix()} Transaction with id ${payload.transactionId} STARTED on ${
+ chargingStation.stationInfo?.chargingStationId
+ }#${connectorId} for idTag '${requestPayload.idTag}'`
)
if (chargingStation.stationInfo?.powerSharedByConnectors === true) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
chargingStation: ChargingStation,
connectorId: number
): Promise<void> {
+ chargingStation.stopMeterValues(connectorId)
const connectorStatus = chargingStation.getConnectorStatus(connectorId)
resetConnectorStatus(connectorStatus)
- chargingStation.stopMeterValues(connectorId)
- if (connectorStatus?.status !== OCPP16ChargePointStatus.Available) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Available
- )
- }
+ await OCPP16ServiceUtils.restoreConnectorStatus(chargingStation, connectorId, connectorStatus)
}
private async handleResponseStopTransaction (