feat(ui): make evses works in the web ui
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 3 May 2023 19:26:19 +0000 (21:26 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 3 May 2023 19:26:19 +0000 (21:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
package.json
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPServiceUtils.ts
ui/web/package.json
ui/web/src/components/charging-stations/CSData.vue
ui/web/src/composables/UIClient.ts

index a7ca5d5319e9fe1827179942c4ffd0aea973ce6a..4396a99129577ea7ddeb42c2c117cebec547c49c 100644 (file)
@@ -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",
index f18951635f72614fe0b284670668d655a3af5d63..5d6ee757a7009f7dea6b3f31ea999eedc4e32bab 100644 (file)
@@ -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;
index f0ad1ca668f84bd72060eb2cf57c7a1d7fe63d85..1326cde4b3047db7e3d4a1bbce7781eaf3bc8cb4 100644 (file)
@@ -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;
   }
index 6c9e262b18415ae9b27712847841c1dc35f698b8..04d95c0e7b53f57b9ae1be84ff734da9b1bb58f4 100644 (file)
@@ -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",
index da25b46b10c8ee0fadce37fbb547d87899137068..1c51647e6ce5f686925b57fb25bde32a29c2698b 100644 (file)
@@ -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 {
index f7fc9052c96173ed9ae636ff9f513881573ca6ab..7c0c06c121be0da21190687cc2ea752feb197fd3 100644 (file)
@@ -17,12 +17,12 @@ type ResponseHandler = {
 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() {
@@ -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<ResponsePayload> {
@@ -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<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(
@@ -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);