Commit | Line | Data |
---|---|---|
179ed367 JB |
1 | import { |
2 | OutputFormat, | |
3 | buildChargingStationAutomaticTransactionGeneratorConfiguration, | |
4 | buildConnectorsStatus, | |
5 | buildEvsesStatus, | |
6 | } from './ChargingStationConfigurationUtils'; | |
7671fa0b | 7 | import type { ChargingStation } from '../charging-station'; |
32de5a57 | 8 | import { |
e0b0ee21 JB |
9 | type ChargingStationData, |
10 | type ChargingStationWorkerMessage, | |
32de5a57 | 11 | ChargingStationWorkerMessageEvents, |
268a74bb JB |
12 | type Statistics, |
13 | } from '../types'; | |
32de5a57 LM |
14 | |
15 | export class MessageChannelUtils { | |
16 | private constructor() { | |
17 | // This is intentional | |
18 | } | |
19 | ||
20 | public static buildStartedMessage( | |
21 | chargingStation: ChargingStation | |
22 | ): ChargingStationWorkerMessage<ChargingStationData> { | |
23 | return { | |
721646e9 | 24 | id: ChargingStationWorkerMessageEvents.started, |
32de5a57 LM |
25 | data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), |
26 | }; | |
27 | } | |
28 | ||
29 | public static buildStoppedMessage( | |
30 | chargingStation: ChargingStation | |
31 | ): ChargingStationWorkerMessage<ChargingStationData> { | |
32 | return { | |
721646e9 | 33 | id: ChargingStationWorkerMessageEvents.stopped, |
32de5a57 LM |
34 | data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), |
35 | }; | |
36 | } | |
37 | ||
38 | public static buildUpdatedMessage( | |
39 | chargingStation: ChargingStation | |
40 | ): ChargingStationWorkerMessage<ChargingStationData> { | |
41 | return { | |
721646e9 | 42 | id: ChargingStationWorkerMessageEvents.updated, |
32de5a57 LM |
43 | data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), |
44 | }; | |
45 | } | |
46 | ||
47 | public static buildPerformanceStatisticsMessage( | |
48 | statistics: Statistics | |
49 | ): ChargingStationWorkerMessage<Statistics> { | |
50 | return { | |
721646e9 | 51 | id: ChargingStationWorkerMessageEvents.performanceStatistics, |
32de5a57 LM |
52 | data: statistics, |
53 | }; | |
54 | } | |
55 | ||
56 | private static buildChargingStationDataPayload( | |
57 | chargingStation: ChargingStation | |
58 | ): ChargingStationData { | |
59 | return { | |
452a82ca | 60 | started: chargingStation.started, |
8d8599f0 | 61 | stationInfo: chargingStation.stationInfo, |
179ed367 | 62 | connectors: buildConnectorsStatus(chargingStation), |
09989bb8 | 63 | evses: buildEvsesStatus(chargingStation, OutputFormat.worker), |
8d8599f0 JB |
64 | ocppConfiguration: chargingStation.ocppConfiguration, |
65 | wsState: chargingStation?.wsConnection?.readyState, | |
66 | bootNotificationResponse: chargingStation.bootNotificationResponse, | |
5e3cb728 | 67 | ...(chargingStation.automaticTransactionGenerator && { |
179ed367 JB |
68 | automaticTransactionGenerator: |
69 | buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation), | |
5e3cb728 | 70 | }), |
32de5a57 LM |
71 | }; |
72 | } | |
73 | } |