Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Properly name OCPP command handler methods
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Apr 15, 2022
1 parent de17a56 commit f7f98c6
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 64 deletions.
12 changes: 6 additions & 6 deletions src/charging-station/AutomaticTransactionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export default class AutomaticTransactionGenerator {
this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
// Authorize idTag
const authorizeResponse: AuthorizeResponse =
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
AuthorizeRequest,
AuthorizeResponse
>(RequestCommand.AUTHORIZE, {
Expand All @@ -289,7 +289,7 @@ export default class AutomaticTransactionGenerator {
this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
// Start transaction
startResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
StartTransactionRequest,
StartTransactionResponse
>(RequestCommand.START_TRANSACTION, {
Expand All @@ -305,7 +305,7 @@ export default class AutomaticTransactionGenerator {
}
logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
// Start transaction
startResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
StartTransactionRequest,
StartTransactionResponse
>(RequestCommand.START_TRANSACTION, {
Expand All @@ -316,7 +316,7 @@ export default class AutomaticTransactionGenerator {
return startResponse;
}
logger.info(this.logPrefix(connectorId) + ' start transaction without an idTag');
startResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
startResponse = await this.chargingStation.ocppRequestService.requestHandler<
StartTransactionRequest,
StartTransactionResponse
>(RequestCommand.START_TRANSACTION, { connectorId });
Expand Down Expand Up @@ -345,7 +345,7 @@ export default class AutomaticTransactionGenerator {
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
MeterValuesRequest,
MeterValuesResponse
>(RequestCommand.METER_VALUES, {
Expand All @@ -354,7 +354,7 @@ export default class AutomaticTransactionGenerator {
meterValue: transactionEndMeterValue,
});
}
stopResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
stopResponse = await this.chargingStation.ocppRequestService.requestHandler<
StopTransactionRequest,
StopTransactionResponse
>(RequestCommand.STOP_TRANSACTION, {
Expand Down
38 changes: 19 additions & 19 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export default class ChargingStation {
) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.heartbeatSetInterval = setInterval(async (): Promise<void> => {
await this.ocppRequestService.sendMessageHandler<HeartbeatRequest, HeartbeatResponse>(
await this.ocppRequestService.requestHandler<HeartbeatRequest, HeartbeatResponse>(
RequestCommand.HEARTBEAT
);
}, this.getHeartbeatInterval());
Expand Down Expand Up @@ -514,7 +514,7 @@ export default class ChargingStation {
this.getConnectorStatus(connectorId).transactionId,
interval
);
await this.ocppRequestService.sendMessageHandler<MeterValuesRequest, MeterValuesResponse>(
await this.ocppRequestService.requestHandler<MeterValuesRequest, MeterValuesResponse>(
RequestCommand.METER_VALUES,
{
connectorId,
Expand Down Expand Up @@ -619,7 +619,7 @@ export default class ChargingStation {
await this.stopMessageSequence(reason);
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
>(RequestCommand.STATUS_NOTIFICATION, {
Expand Down Expand Up @@ -1391,7 +1391,7 @@ export default class ChargingStation {
// Send BootNotification
let registrationRetryCount = 0;
do {
this.bootNotificationResponse = await this.ocppRequestService.sendMessageHandler<
this.bootNotificationResponse = await this.ocppRequestService.requestHandler<
BootNotificationRequest,
BootNotificationResponse
>(
Expand Down Expand Up @@ -1510,7 +1510,7 @@ export default class ChargingStation {
)}`
);
// Process the call
await this.ocppIncomingRequestService.handleRequest(
await this.ocppIncomingRequestService.incomingRequestHandler(
messageId,
commandName,
commandPayload
Expand Down Expand Up @@ -1763,7 +1763,7 @@ export default class ChargingStation {

private async startMessageSequence(): Promise<void> {
if (this.stationInfo.autoRegister) {
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
BootNotificationRequest,
BootNotificationResponse
>(
Expand Down Expand Up @@ -1796,7 +1796,7 @@ export default class ChargingStation {
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template at startup
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
>(RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -1812,7 +1812,7 @@ export default class ChargingStation {
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template after reset
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
>(RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -1824,7 +1824,7 @@ export default class ChargingStation {
this.getConnectorStatus(connectorId).bootStatus;
} else if (!this.stopped && this.getConnectorStatus(connectorId)?.status) {
// Send previous status at template reload
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
>(RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -1834,7 +1834,7 @@ export default class ChargingStation {
});
} else {
// Send default status
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
StatusNotificationRequest,
StatusNotificationResponse
>(RequestCommand.STATUS_NOTIFICATION, {
Expand Down Expand Up @@ -1888,16 +1888,16 @@ export default class ChargingStation {
connectorId,
this.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
await this.ocppRequestService.sendMessageHandler<
MeterValuesRequest,
MeterValuesResponse
>(RequestCommand.METER_VALUES, {
connectorId,
transactionId,
meterValue: transactionEndMeterValue,
});
await this.ocppRequestService.requestHandler<MeterValuesRequest, MeterValuesResponse>(
RequestCommand.METER_VALUES,
{
connectorId,
transactionId,
meterValue: transactionEndMeterValue,
}
);
}
await this.ocppRequestService.sendMessageHandler<
await this.ocppRequestService.requestHandler<
StopTransactionRequest,
StopTransactionResponse
>(RequestCommand.STOP_TRANSACTION, {
Expand Down
2 changes: 1 addition & 1 deletion src/charging-station/UIWebSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class UIWebSocketServer extends Server {
}
this.uiServices
.get(version)
.handleMessage(command, payload)
.messageHandler(command, payload)
.catch(() => {
logger.error(
`${this.logPrefix()} Error while handling command %s message: %j`,
Expand Down
40 changes: 20 additions & 20 deletions src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
]);
}

public async handleRequest(
public async incomingRequestHandler(
messageId: string,
commandName: OCPP16IncomingRequestCommand,
commandPayload: JsonType
Expand Down Expand Up @@ -235,7 +235,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16MeterValuesRequest,
OCPP16MeterValuesResponse
>(OCPP16RequestCommand.METER_VALUES, {
Expand All @@ -244,7 +244,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
meterValue: transactionEndMeterValue,
});
}
const stopResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
const stopResponse = await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StopTransactionRequest,
OCPP16StopTransactionResponse
>(OCPP16RequestCommand.STOP_TRANSACTION, {
Expand All @@ -258,7 +258,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
}
return Constants.OCPP_RESPONSE_UNLOCK_FAILED;
}
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(OCPP16RequestCommand.STATUS_NOTIFICATION, {
Expand Down Expand Up @@ -530,7 +530,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
}
this.chargingStation.getConnectorStatus(id).availability = commandPayload.type;
if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(OCPP16RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -555,7 +555,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(OCPP16RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -575,7 +575,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
const transactionConnectorId = commandPayload.connectorId;
const connectorStatus = this.chargingStation.getConnectorStatus(transactionConnectorId);
if (transactionConnectorId) {
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(OCPP16RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -599,7 +599,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
} else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
connectorStatus.authorizeIdTag = commandPayload.idTag;
const authorizeResponse: OCPP16AuthorizeResponse =
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16AuthorizeRequest,
OCPP16AuthorizeResponse
>(OCPP16RequestCommand.AUTHORIZE, {
Expand All @@ -624,7 +624,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
connectorStatus.transactionRemoteStarted = true;
if (
(
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StartTransactionRequest,
OCPP16StartTransactionResponse
>(OCPP16RequestCommand.START_TRANSACTION, {
Expand Down Expand Up @@ -669,7 +669,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
connectorStatus.transactionRemoteStarted = true;
if (
(
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StartTransactionRequest,
OCPP16StartTransactionResponse
>(OCPP16RequestCommand.START_TRANSACTION, {
Expand Down Expand Up @@ -715,7 +715,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(OCPP16RequestCommand.STATUS_NOTIFICATION, {
Expand Down Expand Up @@ -772,7 +772,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
connectorId > 0 &&
this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
) {
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
>(OCPP16RequestCommand.STATUS_NOTIFICATION, {
Expand All @@ -793,7 +793,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16MeterValuesRequest,
OCPP16MeterValuesResponse
>(OCPP16RequestCommand.METER_VALUES, {
Expand All @@ -802,7 +802,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
meterValue: transactionEndMeterValue,
});
}
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
OCPP16StopTransactionRequest,
OCPP16StopTransactionResponse
>(OCPP16RequestCommand.STOP_TRANSACTION, {
Expand Down Expand Up @@ -868,7 +868,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
info.bytes / 1024
} bytes transferred from diagnostics archive ${info.name}`
);
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
DiagnosticsStatusNotificationRequest,
DiagnosticsStatusNotificationResponse
>(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
Expand All @@ -880,7 +880,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
uri.pathname + diagnosticsArchive
);
if (uploadResponse.code === 226) {
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
DiagnosticsStatusNotificationRequest,
DiagnosticsStatusNotificationResponse
>(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
Expand All @@ -907,7 +907,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
);
} catch (error) {
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
DiagnosticsStatusNotificationRequest,
DiagnosticsStatusNotificationResponse
>(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
Expand All @@ -928,7 +928,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
uri.protocol
} to transfer the diagnostic logs archive`
);
await this.chargingStation.ocppRequestService.sendMessageHandler<
await this.chargingStation.ocppRequestService.requestHandler<
DiagnosticsStatusNotificationRequest,
DiagnosticsStatusNotificationResponse
>(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
Expand All @@ -955,7 +955,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
case MessageTrigger.BootNotification:
setTimeout(() => {
this.chargingStation.ocppRequestService
.sendMessageHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
.requestHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
OCPP16RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel:
Expand Down Expand Up @@ -987,7 +987,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
case MessageTrigger.Heartbeat:
setTimeout(() => {
this.chargingStation.ocppRequestService
.sendMessageHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
.requestHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
OCPP16RequestCommand.HEARTBEAT,
null,
{
Expand Down
6 changes: 3 additions & 3 deletions src/charging-station/ocpp/1.6/OCPP16RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export default class OCPP16RequestService extends OCPPRequestService {
super(chargingStation, ocppResponseService);
}

public async sendMessageHandler<Request extends JsonType, Response extends JsonType>(
public async requestHandler<Request extends JsonType, Response extends JsonType>(
commandName: OCPP16RequestCommand,
commandParams?: JsonType,
params?: SendParams
): Promise<Response> {
if (Object.values(OCPP16RequestCommand).includes(commandName)) {
return (await this.sendMessage(
Utils.generateUUID(),
this.buildCommandPayload<Request>(commandName, commandParams),
this.buildRequestPayload<Request>(commandName, commandParams),
commandName,
params
)) as unknown as Response;
Expand All @@ -43,7 +43,7 @@ export default class OCPP16RequestService extends OCPPRequestService {
);
}

private buildCommandPayload<Request extends JsonType>(
private buildRequestPayload<Request extends JsonType>(
commandName: OCPP16RequestCommand,
commandParams?: JsonType
): Request {
Expand Down
Loading

0 comments on commit f7f98c6

Please sign in to comment.