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