UI server: permit to address all charging stations
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 1 Sep 2022 22:29:06 +0000 (00:29 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 1 Sep 2022 22:29:06 +0000 (00:29 +0200)
Not specifying hashIds in payload means all

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/WorkerBroadcastChannel.ts

index 714bf0f931d67091029f25a6ce7d2c3bf8c9948e..ecc3ab49a36a44fc5a38aab0ee120460c6a7e887 100644 (file)
@@ -42,22 +42,24 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
 
     const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest;
 
-    if (
-      requestPayload?.hashId === undefined &&
-      requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false
-    ) {
-      return;
-    }
-    if (
-      requestPayload?.hashIds === undefined &&
-      requestPayload?.hashId !== this.chargingStation.stationInfo.hashId
-    ) {
-      return;
-    }
-    if (requestPayload?.hashId !== undefined) {
-      logger.warn(
-        `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead`
-      );
+    if (requestPayload?.hashIds !== undefined || requestPayload?.hashId !== undefined) {
+      if (
+        requestPayload?.hashId === undefined &&
+        requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false
+      ) {
+        return;
+      }
+      if (
+        requestPayload?.hashIds === undefined &&
+        requestPayload?.hashId !== this.chargingStation.stationInfo.hashId
+      ) {
+        return;
+      }
+      if (requestPayload?.hashId !== undefined) {
+        logger.warn(
+          `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead`
+        );
+      }
     }
 
     let responsePayload: BroadcastChannelResponsePayload;
index dba83cbb01fccdd367143906d53f8fd7a4d280bc..b19bf946dc633db77e5c690e75dd4b921de6868a 100644 (file)
@@ -1,6 +1,7 @@
 import { BroadcastChannel } from 'worker_threads';
 
 import BaseError from '../exception/BaseError';
+import type { JsonType } from '../types/JsonType';
 import type {
   BroadcastChannelRequest,
   BroadcastChannelResponse,
@@ -20,11 +21,11 @@ export default abstract class WorkerBroadcastChannel extends BroadcastChannel {
     this.postMessage(response);
   }
 
-  protected isRequest(message: any): boolean {
+  protected isRequest(message: JsonType[]): boolean {
     return Array.isArray(message) && message.length === 3;
   }
 
-  protected isResponse(message: any): boolean {
+  protected isResponse(message: JsonType[]): boolean {
     return Array.isArray(message) && message.length === 2;
   }