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