import type { JSONSchemaType } from 'ajv';
import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
-import { type ChargingStation, ChargingStationConfigurationUtils } from '../../../charging-station';
+import { type ChargingStation, addConfigurationKey } from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
ErrorType,
// }
super(OCPPVersion.VERSION_20);
this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
- [OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
- [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
- [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ [
+ OCPP20RequestCommand.BOOT_NOTIFICATION,
+ this.handleResponseBootNotification.bind(this) as ResponseHandler,
+ ],
+ [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [
+ OCPP20RequestCommand.STATUS_NOTIFICATION,
+ this.emptyResponseHandler.bind(this) as ResponseHandler,
+ ],
]);
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
) => 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 ||
) {
try {
this.validatePayload(chargingStation, commandName, payload);
- await this.responseHandlers.get(commandName)(chargingStation, payload, requestPayload);
+ await this.responseHandlers.get(commandName)!(chargingStation, payload, requestPayload);
} catch (error) {
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.responseHandler: Handle response error:`,
return this.validateResponsePayload(
chargingStation,
commandName,
- this.jsonSchemas.get(commandName),
+ this.jsonSchemas.get(commandName)!,
payload,
);
}
payload: OCPP20BootNotificationResponse,
): void {
if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
- ChargingStationConfigurationUtils.addConfigurationKey(
+ addConfigurationKey(
chargingStation,
OCPP20OptionalVariableName.HeartbeatInterval,
payload.interval.toString(),