From 18057587414006953ed112f315807d64ddb11bfd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 2 Sep 2022 00:29:06 +0200 Subject: [PATCH] UI server: permit to address all charging stations MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Not specifying hashIds in payload means all Signed-off-by: Jérôme Benoit --- .../ChargingStationWorkerBroadcastChannel.ts | 34 ++++++++++--------- .../WorkerBroadcastChannel.ts | 5 +-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 714bf0f9..ecc3ab49 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -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; diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index dba83cbb..b19bf946 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -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; } -- 2.34.1