Commit | Line | Data |
---|---|---|
66a7748d | 1 | import type { ChargingStation } from '../charging-station/index.js' |
32de5a57 | 2 | import { |
e0b0ee21 JB |
3 | type ChargingStationData, |
4 | type ChargingStationWorkerMessage, | |
32de5a57 | 5 | ChargingStationWorkerMessageEvents, |
276e05ae | 6 | type Statistics |
66a7748d | 7 | } from '../types/index.js' |
4c3f6c20 JB |
8 | import { |
9 | buildChargingStationAutomaticTransactionGeneratorConfiguration, | |
10 | buildConnectorsStatus, | |
11 | buildEvsesStatus, | |
12 | OutputFormat | |
13 | } from './ChargingStationConfigurationUtils.js' | |
32de5a57 | 14 | |
244c1396 JB |
15 | export const buildAddedMessage = ( |
16 | chargingStation: ChargingStation | |
17 | ): ChargingStationWorkerMessage<ChargingStationData> => { | |
18 | return { | |
19 | event: ChargingStationWorkerMessageEvents.added, | |
20 | data: buildChargingStationDataPayload(chargingStation) | |
21 | } | |
22 | } | |
23 | ||
09e5a7a8 JB |
24 | export const buildDeletedMessage = ( |
25 | chargingStation: ChargingStation | |
26 | ): ChargingStationWorkerMessage<ChargingStationData> => { | |
27 | return { | |
28 | event: ChargingStationWorkerMessageEvents.deleted, | |
29 | data: buildChargingStationDataPayload(chargingStation) | |
30 | } | |
31 | } | |
32 | ||
c8faabc8 | 33 | export const buildStartedMessage = ( |
66a7748d | 34 | chargingStation: ChargingStation |
c8faabc8 JB |
35 | ): ChargingStationWorkerMessage<ChargingStationData> => { |
36 | return { | |
8cc482a9 | 37 | event: ChargingStationWorkerMessageEvents.started, |
66a7748d JB |
38 | data: buildChargingStationDataPayload(chargingStation) |
39 | } | |
40 | } | |
32de5a57 | 41 | |
c8faabc8 | 42 | export const buildStoppedMessage = ( |
66a7748d | 43 | chargingStation: ChargingStation |
c8faabc8 JB |
44 | ): ChargingStationWorkerMessage<ChargingStationData> => { |
45 | return { | |
8cc482a9 | 46 | event: ChargingStationWorkerMessageEvents.stopped, |
66a7748d JB |
47 | data: buildChargingStationDataPayload(chargingStation) |
48 | } | |
49 | } | |
32de5a57 | 50 | |
c8faabc8 | 51 | export const buildUpdatedMessage = ( |
66a7748d | 52 | chargingStation: ChargingStation |
c8faabc8 JB |
53 | ): ChargingStationWorkerMessage<ChargingStationData> => { |
54 | return { | |
8cc482a9 | 55 | event: ChargingStationWorkerMessageEvents.updated, |
66a7748d JB |
56 | data: buildChargingStationDataPayload(chargingStation) |
57 | } | |
58 | } | |
32de5a57 | 59 | |
c8faabc8 | 60 | export const buildPerformanceStatisticsMessage = ( |
66a7748d | 61 | statistics: Statistics |
c8faabc8 JB |
62 | ): ChargingStationWorkerMessage<Statistics> => { |
63 | return { | |
8cc482a9 | 64 | event: ChargingStationWorkerMessageEvents.performanceStatistics, |
66a7748d JB |
65 | data: statistics |
66 | } | |
67 | } | |
32de5a57 | 68 | |
90dc299a | 69 | const buildChargingStationDataPayload = (chargingStation: ChargingStation): ChargingStationData => { |
c8faabc8 JB |
70 | return { |
71 | started: chargingStation.started, | |
5199f9fd JB |
72 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
73 | stationInfo: chargingStation.stationInfo!, | |
c8faabc8 JB |
74 | connectors: buildConnectorsStatus(chargingStation), |
75 | evses: buildEvsesStatus(chargingStation, OutputFormat.worker), | |
66a7748d | 76 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
e1d9a0f4 | 77 | ocppConfiguration: chargingStation.ocppConfiguration!, |
1d41bc6b | 78 | supervisionUrl: chargingStation.wsConnectionUrl.href, |
5199f9fd | 79 | wsState: chargingStation.wsConnection?.readyState, |
c8faabc8 | 80 | bootNotificationResponse: chargingStation.bootNotificationResponse, |
66a7748d | 81 | ...(chargingStation.automaticTransactionGenerator != null && { |
c8faabc8 | 82 | automaticTransactionGenerator: |
66a7748d JB |
83 | buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation) |
84 | }) | |
85 | } | |
86 | } |