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