From 12f26d4a81773cf8ede8bad4255e36aadf10bce0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 3 May 2023 21:26:19 +0200 Subject: [PATCH] feat(ui): make evses works in the web ui MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package.json | 2 +- src/charging-station/ChargingStation.ts | 6 ++-- src/charging-station/ocpp/OCPPServiceUtils.ts | 10 +++--- ui/web/package.json | 2 +- .../components/charging-stations/CSData.vue | 11 +++++++ ui/web/src/composables/UIClient.ts | 32 +++++++++---------- 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index a7ca5d53..4396a991 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.2.11", "engines": { "node": ">=16.9.0", - "pnpm": ">= 8.0.0" + "pnpm": ">=8.0.0" }, "volta": { "node": "20.0.0", diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index f1895163..5d6ee757 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -2038,7 +2038,8 @@ export class ChargingStation { await OCPPServiceUtils.sendAndSetConnectorStatus( this, connectorId, - connectorBootStatus + connectorBootStatus, + evseId ); } } @@ -2098,7 +2099,8 @@ export class ChargingStation { OCPPServiceUtils.buildStatusNotificationRequest( this, connectorId, - ConnectorStatusEnum.Unavailable + ConnectorStatusEnum.Unavailable, + evseId ) ); delete connectorStatus?.status; diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index f0ad1ca6..1326cde4 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -146,7 +146,8 @@ export class OCPPServiceUtils { 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: @@ -161,7 +162,7 @@ export class OCPPServiceUtils { timestamp: new Date(), connectorStatus: status, connectorId, - evseId: connectorId, + evseId, } as OCPP20StatusNotificationRequest; default: throw new BaseError('Cannot build status notification payload: OCPP version not supported'); @@ -179,7 +180,8 @@ export class OCPPServiceUtils { public static async sendAndSetConnectorStatus( chargingStation: ChargingStation, connectorId: number, - status: ConnectorStatusEnum + status: ConnectorStatusEnum, + evseId?: number ) { OCPPServiceUtils.checkConnectorStatusTransition(chargingStation, connectorId, status); await chargingStation.ocppRequestService.requestHandler< @@ -188,7 +190,7 @@ export class OCPPServiceUtils { >( chargingStation, RequestCommand.STATUS_NOTIFICATION, - OCPPServiceUtils.buildStatusNotificationRequest(chargingStation, connectorId, status) + OCPPServiceUtils.buildStatusNotificationRequest(chargingStation, connectorId, status, evseId) ); chargingStation.getConnectorStatus(connectorId).status = status; } diff --git a/ui/web/package.json b/ui/web/package.json index 6c9e262b..04d95c0e 100644 --- a/ui/web/package.json +++ b/ui/web/package.json @@ -4,7 +4,7 @@ "readme": "README.md", "engines": { "node": ">=16.9.0", - "pnpm": ">= 8.0.0" + "pnpm": ">=8.0.0" }, "volta": { "node": "20.0.0", diff --git a/ui/web/src/components/charging-stations/CSData.vue b/ui/web/src/components/charging-stations/CSData.vue index da25b46b..1c51647e 100644 --- a/ui/web/src/components/charging-stations/CSData.vue +++ b/ui/web/src/components/charging-stations/CSData.vue @@ -43,6 +43,17 @@ const props = defineProps<{ // }); function getConnectors(): ConnectorStatus[] { + if (Array.isArray(props.chargingStation.evses) && props.chargingStation.evses.length > 0) { + const connectorsStatus: ConnectorStatus[] = []; + for (const [evseId, evseStatus] of props.chargingStation.evses.entries()) { + if (evseId > 0 && Array.isArray(evseStatus.connectors) && evseStatus.connectors.length > 0) { + for (const connector of evseStatus.connectors) { + connectorsStatus.push(connector); + } + } + } + return connectorsStatus; + } return props.chargingStation.connectors?.slice(1); } function getInfo(): ChargingStationInfo { diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index f7fc9052..7c0c06c1 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -17,12 +17,12 @@ type ResponseHandler = { export default class UIClient { private static _instance: UIClient | null = null; - private _ws!: WebSocket; - private _responseHandlers: Map; + private ws!: WebSocket; + private responseHandlers: Map; private constructor() { this.openWS(); - this._responseHandlers = new Map(); + this.responseHandlers = new Map(); } public static getInstance() { @@ -33,7 +33,7 @@ export default class UIClient { } public registerWSonOpenListener(listener: (event: Event) => void) { - this._ws.addEventListener('open', listener); + this.ws.addEventListener('open', listener); } public async startSimulator(): Promise { @@ -111,15 +111,15 @@ export default class UIClient { } 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); }; } @@ -130,15 +130,15 @@ export default class UIClient { resolve: (value: ResponsePayload | PromiseLike) => 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( @@ -151,11 +151,11 @@ export default class UIClient { 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`); } @@ -165,7 +165,7 @@ export default class UIClient { 120 * 1000, Error(`Send request '${command}' message timeout`), () => { - this._responseHandlers.delete(uuid); + this.responseHandlers.delete(uuid); } ); } @@ -179,7 +179,7 @@ export default class UIClient { 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); -- 2.34.1