Cleanup Array.from() usage
[e-mobility-charging-stations-simulator.git] / src / charging-station / MessageChannelUtils.ts
CommitLineData
32de5a57
LM
1import {
2 ChargingStationData,
3 ChargingStationWorkerMessage,
4 ChargingStationWorkerMessageEvents,
5} from '../types/ChargingStationWorker';
6c1761d4 6import type Statistics from '../types/Statistics';
32de5a57
LM
7import type ChargingStation from './ChargingStation';
8
9export class MessageChannelUtils {
10 private constructor() {
11 // This is intentional
12 }
13
14 public static buildStartedMessage(
15 chargingStation: ChargingStation
16 ): ChargingStationWorkerMessage<ChargingStationData> {
17 return {
18 id: ChargingStationWorkerMessageEvents.STARTED,
19 data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
20 };
21 }
22
23 public static buildStoppedMessage(
24 chargingStation: ChargingStation
25 ): ChargingStationWorkerMessage<ChargingStationData> {
26 return {
27 id: ChargingStationWorkerMessageEvents.STOPPED,
28 data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
29 };
30 }
31
32 public static buildUpdatedMessage(
33 chargingStation: ChargingStation
34 ): ChargingStationWorkerMessage<ChargingStationData> {
35 return {
36 id: ChargingStationWorkerMessageEvents.UPDATED,
37 data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation),
38 };
39 }
40
41 public static buildPerformanceStatisticsMessage(
42 statistics: Statistics
43 ): ChargingStationWorkerMessage<Statistics> {
44 return {
45 id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS,
46 data: statistics,
47 };
48 }
49
50 private static buildChargingStationDataPayload(
51 chargingStation: ChargingStation
52 ): ChargingStationData {
53 return {
54 hashId: chargingStation.hashId,
55 stationInfo: chargingStation.stationInfo,
89b7a234 56 stopped: chargingStation.stopped,
c76d7c1b 57 bootNotificationResponse: chargingStation.bootNotificationResponse,
bbc6c092 58 connectors: [...chargingStation.connectors.values()].map(
17bfa1b6 59 // eslint-disable-next-line @typescript-eslint/no-unused-vars
fc040c43
JB
60 ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
61 ),
32de5a57
LM
62 };
63 }
64}