this.chargingStation = chargingStation;
this.ocppResponseService = ocppResponseService;
this.sendMessageHandler.bind(this);
+ this.sendResult.bind(this);
+ this.sendError.bind(this);
}
public static getInstance<T extends OCPPRequestService>(
chargingStation: ChargingStation,
ocppResponseService: OCPPResponseService
): T {
- if (!OCPPRequestService.instances.has(chargingStation.id)) {
+ if (!OCPPRequestService.instances.has(chargingStation.hashId)) {
OCPPRequestService.instances.set(
- chargingStation.id,
+ chargingStation.hashId,
new this(chargingStation, ocppResponseService)
);
}
- return OCPPRequestService.instances.get(chargingStation.id) as T;
+ return OCPPRequestService.instances.get(chargingStation.hashId) as T;
}
public async sendResult(
// FIXME: Handle sending error
this.chargingStation.wsConnection.send(messageToSend);
PerformanceStatistics.endMeasure(commandName, beginId);
+ logger.debug(
+ `${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
+ messageType
+ )} payload: ${messageToSend}`
+ );
} else if (!params.skipBufferingOnError) {
// Buffer it
this.chargingStation.bufferMessage(messageToSend);
resolve(payload);
} catch (error) {
reject(error);
- throw error;
} finally {
self.chargingStation.requests.delete(messageId);
}
return messageToSend;
}
+ private getMessageTypeString(messageType: MessageType): string {
+ switch (messageType) {
+ case MessageType.CALL_MESSAGE:
+ return 'request';
+ case MessageType.CALL_RESULT_MESSAGE:
+ return 'response';
+ case MessageType.CALL_ERROR_MESSAGE:
+ return 'error';
+ }
+ }
+
private handleRequestError(
commandName: RequestCommand | IncomingRequestCommand,
error: Error,
}
}
- public abstract sendMessageHandler(
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ public abstract sendMessageHandler<Request extends JsonType, Response extends JsonType>(
commandName: RequestCommand,
commandParams?: JsonType,
params?: SendParams
- ): Promise<ResponseType>;
+ ): Promise<Response>;
}