) => boolean;
}
- public async incomingRequestHandler(
+ public async incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
messageId: string,
commandName: OCPP16IncomingRequestCommand,
- commandPayload: JsonType,
+ commandPayload: ReqType,
): Promise<void> {
- let response: JsonType;
+ let response: ResType;
if (
chargingStation.getOcppStrictCompliance() === true &&
chargingStation.inPendingState() === true &&
try {
this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
- response = await this.incomingRequestHandlers.get(commandName)!(
+ response = (await this.incomingRequestHandlers.get(commandName)!(
chargingStation,
commandPayload,
- );
+ )) as ResType;
} catch (error) {
// Log
logger.error(
) => boolean;
}
- public async responseHandler(
+ public async responseHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
commandName: OCPP16RequestCommand,
- payload: JsonType,
- requestPayload: JsonType,
+ payload: ResType,
+ requestPayload: ReqType,
): Promise<void> {
if (
chargingStation.isRegistered() === true ||
) => boolean;
}
- public async incomingRequestHandler(
+ public async incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
messageId: string,
commandName: OCPP20IncomingRequestCommand,
- commandPayload: JsonType,
+ commandPayload: ReqType,
): Promise<void> {
- let response: JsonType;
+ let response: ResType;
if (
chargingStation.getOcppStrictCompliance() === true &&
chargingStation.inPendingState() === true &&
try {
this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
- response = await this.incomingRequestHandlers.get(commandName)!(
+ response = (await this.incomingRequestHandlers.get(commandName)!(
chargingStation,
commandPayload,
- );
+ )) as ResType;
} catch (error) {
// Log
logger.error(
) => boolean;
}
- public async responseHandler(
+ public async responseHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
commandName: OCPP20RequestCommand,
- payload: JsonType,
- requestPayload: JsonType,
+ payload: ResType,
+ requestPayload: ReqType,
): Promise<void> {
if (
chargingStation.isRegistered() === true ||
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.incomingRequestHandler = this.incomingRequestHandler.bind(this) as (
+ this.incomingRequestHandler = this.incomingRequestHandler.bind(this) as <
+ ReqType extends JsonType,
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ ResType extends JsonType,
+ >(
chargingStation: ChargingStation,
messageId: string,
commandName: IncomingRequestCommand,
- commandPayload: JsonType,
+ commandPayload: ReqType,
) => Promise<void>;
this.validateIncomingRequestPayload = this.validateIncomingRequestPayload.bind(this) as <
T extends JsonType,
return OCPPConstants.OCPP_RESPONSE_REJECTED;
}
- public abstract incomingRequestHandler(
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ public abstract incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
messageId: string,
commandName: IncomingRequestCommand,
- commandPayload: JsonType,
+ commandPayload: ReqType,
): Promise<void>;
}
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.responseHandler = this.responseHandler.bind(this) as (
+ this.responseHandler = this.responseHandler.bind(this) as <
+ ReqType extends JsonType,
+ ResType extends JsonType,
+ >(
chargingStation: ChargingStation,
commandName: RequestCommand,
- payload: JsonType,
- requestPayload: JsonType,
+ payload: ResType,
+ requestPayload: ReqType,
) => Promise<void>;
this.validateResponsePayload = this.validateResponsePayload.bind(this) as <T extends JsonType>(
chargingStation: ChargingStation,
/* This is intentional */
}
- public abstract responseHandler(
+ public abstract responseHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand,
- payload: JsonType,
- requestPayload: JsonType,
+ payload: ResType,
+ requestPayload: ReqType,
): Promise<void>;
}