- ): Promise<DefaultResponse> {
- const transactionConnectorId = commandPayload.connectorId;
- const connectorStatus = this.chargingStation.getConnectorStatus(transactionConnectorId);
- if (transactionConnectorId) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: transactionConnectorId,
- status: OCPP16ChargePointStatus.PREPARING,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
- connectorStatus.status = OCPP16ChargePointStatus.PREPARING;
- if (this.chargingStation.isChargingStationAvailable() && connectorStatus) {
- // Check if authorized
- if (this.chargingStation.getAuthorizeRemoteTxRequests()) {
- let authorized = false;
- if (
- this.chargingStation.getLocalAuthListEnabled() &&
- this.chargingStation.hasAuthorizedTags() &&
- this.chargingStation.authorizedTags.find((value) => value === commandPayload.idTag)
- ) {
- connectorStatus.localAuthorizeIdTag = commandPayload.idTag;
- connectorStatus.idTagLocalAuthorized = true;
- authorized = true;
- } else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
- connectorStatus.authorizeIdTag = commandPayload.idTag;
- const authorizeResponse: OCPP16AuthorizeResponse =
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
- OCPP16RequestCommand.AUTHORIZE,
- {
- idTag: commandPayload.idTag,
- }
- )) as OCPP16AuthorizeResponse;
- if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- authorized = true;
- }
- } else {
- logger.warn(
- `${this.chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
- );
- }
- if (authorized) {
- // Authorization successful, start transaction
- if (
- this.setRemoteStartTransactionChargingProfile(
- transactionConnectorId,
- commandPayload.chargingProfile
- )
- ) {
- connectorStatus.transactionRemoteStarted = true;
- if (
- (
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
- OCPP16RequestCommand.START_TRANSACTION,
- {
- connectorId: transactionConnectorId,
- idTag: commandPayload.idTag,
- }
- )) as OCPP16StartTransactionResponse
- ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
- ) {
- logger.debug(
- this.chargingStation.logPrefix() +
- ' Transaction remotely STARTED on ' +
- this.chargingStation.stationInfo.chargingStationId +
- '#' +
- transactionConnectorId.toString() +
- ' for idTag ' +
- commandPayload.idTag
- );
- return Constants.OCPP_RESPONSE_ACCEPTED;
- }
- return this.notifyRemoteStartTransactionRejected(
- transactionConnectorId,
- commandPayload.idTag
- );
- }
- return this.notifyRemoteStartTransactionRejected(
- transactionConnectorId,
- commandPayload.idTag
- );
- }
- return this.notifyRemoteStartTransactionRejected(
- transactionConnectorId,
- commandPayload.idTag
- );
- }
- // No authorization check required, start transaction
- if (
- this.setRemoteStartTransactionChargingProfile(
- transactionConnectorId,
- commandPayload.chargingProfile
- )
- ) {
- connectorStatus.transactionRemoteStarted = true;
- if (
- (
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
- OCPP16RequestCommand.START_TRANSACTION,
- {
- connectorId: transactionConnectorId,
- idTag: commandPayload.idTag,
- }
- )) as OCPP16StartTransactionResponse
- ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
- ) {
- logger.debug(
- this.chargingStation.logPrefix() +
- ' Transaction remotely STARTED on ' +
- this.chargingStation.stationInfo.chargingStationId +
- '#' +
- transactionConnectorId.toString() +
- ' for idTag ' +
- commandPayload.idTag
- );
- return Constants.OCPP_RESPONSE_ACCEPTED;
- }
- return this.notifyRemoteStartTransactionRejected(
- transactionConnectorId,
- commandPayload.idTag
- );
- }
- return this.notifyRemoteStartTransactionRejected(
- transactionConnectorId,
- commandPayload.idTag
- );
- }
- return this.notifyRemoteStartTransactionRejected(
+ ): Promise<GenericResponse> {
+ const { connectorId: transactionConnectorId, idTag, chargingProfile } = commandPayload
+ if (!chargingStation.hasConnector(transactionConnectorId)) {
+ return await this.notifyRemoteStartTransactionRejected(
+ chargingStation,
+ transactionConnectorId,
+ idTag
+ )
+ }
+ if (
+ !chargingStation.isChargingStationAvailable() ||
+ !chargingStation.isConnectorAvailable(transactionConnectorId)
+ ) {
+ return await this.notifyRemoteStartTransactionRejected(
+ chargingStation,
+ transactionConnectorId,
+ idTag
+ )
+ }
+ // idTag authorization check required
+ if (
+ chargingStation.getAuthorizeRemoteTxRequests() &&
+ !(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, transactionConnectorId, idTag))
+ ) {
+ return await this.notifyRemoteStartTransactionRejected(
+ chargingStation,
+ transactionConnectorId,
+ idTag
+ )
+ }
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ transactionConnectorId,
+ OCPP16ChargePointStatus.Preparing
+ )
+ if (
+ chargingProfile != null &&
+ !this.setRemoteStartTransactionChargingProfile(
+ chargingStation,