export default class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
public async handleRequest(messageId: string, commandName: OCPP16IncomingRequestCommand, commandPayload: Record<string, unknown>): Promise<void> {
let response;
+ const methodName = `handleRequest${commandName}`;
// Call
- if (typeof this['handleRequest' + commandName] === 'function') {
+ if (typeof this[methodName] === 'function') {
try {
// Call the method to build the response
- response = await this['handleRequest' + commandName](commandPayload);
+ response = await this[methodName](commandPayload);
} catch (error) {
// Log
logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error);
}
if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
const transactionId = this.chargingStation.getConnector(connectorId).transactionId;
- const stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getTransactionMeterStop(transactionId), this.chargingStation.getTransactionIdTag(transactionId), OCPP16StopTransactionReason.UNLOCK_COMMAND);
+ const stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId,
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ this.chargingStation.getTransactionIdTag(transactionId),
+ OCPP16StopTransactionReason.UNLOCK_COMMAND);
if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
return Constants.OCPP_RESPONSE_UNLOCKED;
}
let clearedCP = false;
for (const connector in this.chargingStation.connectors) {
if (!Utils.isEmptyArray(this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles)) {
- this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
+ this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
let clearCurrentCP = false;
if (chargingProfile.chargingProfileId === commandPayload.id) {
clearCurrentCP = true;
logger.debug(this.chargingStation.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation.stationInfo.chargingStationId + '#' + transactionConnectorID.toString() + ' for idTag ' + commandPayload.idTag);
return Constants.OCPP_RESPONSE_ACCEPTED;
}
- logger.error(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag);
+ logger.warn(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag);
return Constants.OCPP_RESPONSE_REJECTED;
}
await this.chargingStation.ocppRequestService.sendStatusNotification(transactionConnectorID, OCPP16ChargePointStatus.PREPARING);
logger.debug(this.chargingStation.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation.stationInfo.chargingStationId + '#' + transactionConnectorID.toString() + ' for idTag ' + commandPayload.idTag);
return Constants.OCPP_RESPONSE_ACCEPTED;
}
- logger.error(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on unavailable connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag);
+ logger.warn(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on unavailable connector Id ' + transactionConnectorID.toString() + ', idTag ' + commandPayload.idTag);
return Constants.OCPP_RESPONSE_REJECTED;
}
if (Utils.convertToInt(connector) > 0 && this.chargingStation.getConnector(Utils.convertToInt(connector))?.transactionId === transactionId) {
await this.chargingStation.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), OCPP16ChargePointStatus.FINISHING);
this.chargingStation.getConnector(Utils.convertToInt(connector)).status = OCPP16ChargePointStatus.FINISHING;
- await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getTransactionMeterStop(transactionId), this.chargingStation.getTransactionIdTag(transactionId));
+ await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ this.chargingStation.getTransactionIdTag(transactionId));
return Constants.OCPP_RESPONSE_ACCEPTED;
}
}