From: Jérôme Benoit Date: Thu, 1 Sep 2022 22:29:06 +0000 (+0200) Subject: UI server: permit to address all charging stations X-Git-Tag: v1.1.70~26 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=18057587414006953ed112f315807d64ddb11bfd;p=e-mobility-charging-stations-simulator.git UI server: permit to address all charging stations Not specifying hashIds in payload means all Signed-off-by: Jérôme Benoit --- 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; }