public static buildStatusNotificationRequest(
chargingStation: ChargingStation,
connectorId: number,
- status: ConnectorStatusEnum
+ status: ConnectorStatusEnum,
+ evseId?: number
): StatusNotificationRequest {
switch (chargingStation.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16) {
case OCPPVersion.VERSION_16:
timestamp: new Date(),
connectorStatus: status,
connectorId,
- evseId: connectorId,
+ evseId,
} as OCPP20StatusNotificationRequest;
default:
throw new BaseError('Cannot build status notification payload: OCPP version not supported');
public static async sendAndSetConnectorStatus(
chargingStation: ChargingStation,
connectorId: number,
- status: ConnectorStatusEnum
+ status: ConnectorStatusEnum,
+ evseId?: number
) {
OCPPServiceUtils.checkConnectorStatusTransition(chargingStation, connectorId, status);
await chargingStation.ocppRequestService.requestHandler<
>(
chargingStation,
RequestCommand.STATUS_NOTIFICATION,
- OCPPServiceUtils.buildStatusNotificationRequest(chargingStation, connectorId, status)
+ OCPPServiceUtils.buildStatusNotificationRequest(chargingStation, connectorId, status, evseId)
);
chargingStation.getConnectorStatus(connectorId).status = status;
}
export default class UIClient {
private static _instance: UIClient | null = null;
- private _ws!: WebSocket;
- private _responseHandlers: Map<string, ResponseHandler>;
+ private ws!: WebSocket;
+ private responseHandlers: Map<string, ResponseHandler>;
private constructor() {
this.openWS();
- this._responseHandlers = new Map<string, ResponseHandler>();
+ this.responseHandlers = new Map<string, ResponseHandler>();
}
public static getInstance() {
}
public registerWSonOpenListener(listener: (event: Event) => void) {
- this._ws.addEventListener('open', listener);
+ this.ws.addEventListener('open', listener);
}
public async startSimulator(): Promise<ResponsePayload> {
}
private openWS(): void {
- this._ws = new WebSocket(
+ this.ws = new WebSocket(
`ws://${config.uiServer.host}:${config.uiServer.port}`,
config.uiServer.protocol
);
- this._ws.onmessage = this.responseHandler.bind(this);
- this._ws.onerror = (errorEvent) => {
+ this.ws.onmessage = this.responseHandler.bind(this);
+ this.ws.onerror = (errorEvent) => {
console.error('WebSocket error: ', errorEvent);
};
- this._ws.onclose = (closeEvent) => {
+ this.ws.onclose = (closeEvent) => {
console.info('WebSocket closed: ', closeEvent);
};
}
resolve: (value: ResponsePayload | PromiseLike<ResponsePayload>) => void,
reject: (reason?: any) => void
): void {
- this._responseHandlers.set(id, { procedureName, resolve, reject });
+ this.responseHandlers.set(id, { procedureName, resolve, reject });
}
private getResponseHandler(id: string): ResponseHandler | undefined {
- return this._responseHandlers.get(id);
+ return this.responseHandlers.get(id);
}
private deleteResponseHandler(id: string): boolean {
- return this._responseHandlers.delete(id);
+ return this.responseHandlers.delete(id);
}
private async sendRequest(
uuid = crypto.randomUUID();
const msg = JSON.stringify([uuid, command, data]);
- if (this._ws.readyState !== WebSocket.OPEN) {
+ if (this.ws.readyState !== WebSocket.OPEN) {
this.openWS();
}
- if (this._ws.readyState === WebSocket.OPEN) {
- this._ws.send(msg);
+ if (this.ws.readyState === WebSocket.OPEN) {
+ this.ws.send(msg);
} else {
throw new Error(`Send request '${command}' message: connection not opened`);
}
120 * 1000,
Error(`Send request '${command}' message timeout`),
() => {
- this._responseHandlers.delete(uuid);
+ this.responseHandlers.delete(uuid);
}
);
}
const [uuid, responsePayload] = response;
- if (this._responseHandlers.has(uuid) === true) {
+ if (this.responseHandlers.has(uuid) === true) {
switch (responsePayload.status) {
case ResponseStatus.SUCCESS:
this.getResponseHandler(uuid)?.resolve(responsePayload);