build(deps): apply updates
[e-mobility-charging-stations-simulator.git] / src / utils / MessageChannelUtils.ts
1 import {
2 OutputFormat,
3 buildChargingStationAutomaticTransactionGeneratorConfiguration,
4 buildConnectorsStatus,
5 buildEvsesStatus,
6 } from './ChargingStationConfigurationUtils';
7 import type { ChargingStation } from '../charging-station';
8 import {
9 type ChargingStationData,
10 type ChargingStationWorkerMessage,
11 ChargingStationWorkerMessageEvents,
12 type Statistics,
13 } from '../types';
14
15 export const buildStartedMessage = (
16 chargingStation: ChargingStation
17 ): ChargingStationWorkerMessage<ChargingStationData> => {
18 return {
19 id: ChargingStationWorkerMessageEvents.started,
20 data: buildChargingStationDataPayload(chargingStation),
21 };
22 };
23
24 export const buildStoppedMessage = (
25 chargingStation: ChargingStation
26 ): ChargingStationWorkerMessage<ChargingStationData> => {
27 return {
28 id: ChargingStationWorkerMessageEvents.stopped,
29 data: buildChargingStationDataPayload(chargingStation),
30 };
31 };
32
33 export const buildUpdatedMessage = (
34 chargingStation: ChargingStation
35 ): ChargingStationWorkerMessage<ChargingStationData> => {
36 return {
37 id: ChargingStationWorkerMessageEvents.updated,
38 data: buildChargingStationDataPayload(chargingStation),
39 };
40 };
41
42 export const buildPerformanceStatisticsMessage = (
43 statistics: Statistics
44 ): ChargingStationWorkerMessage<Statistics> => {
45 return {
46 id: ChargingStationWorkerMessageEvents.performanceStatistics,
47 data: statistics,
48 };
49 };
50
51 const buildChargingStationDataPayload = (chargingStation: ChargingStation): ChargingStationData => {
52 return {
53 started: chargingStation.started,
54 stationInfo: chargingStation.stationInfo,
55 connectors: buildConnectorsStatus(chargingStation),
56 evses: buildEvsesStatus(chargingStation, OutputFormat.worker),
57 ocppConfiguration: chargingStation.ocppConfiguration,
58 wsState: chargingStation?.wsConnection?.readyState,
59 bootNotificationResponse: chargingStation.bootNotificationResponse,
60 ...(chargingStation.automaticTransactionGenerator && {
61 automaticTransactionGenerator:
62 buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation),
63 }),
64 };
65 };