| 1 | import { |
| 2 | OutputFormat, |
| 3 | buildChargingStationAutomaticTransactionGeneratorConfiguration, |
| 4 | buildConnectorsStatus, |
| 5 | buildEvsesStatus, |
| 6 | } from './ChargingStationConfigurationUtils'; |
| 7 | import type { ChargingStation } from '../charging-station'; |
| 8 | import { |
| 9 | type ChargingStationData, |
| 10 | type ChargingStationWorkerMessage, |
| 11 | ChargingStationWorkerMessageEvents, |
| 12 | type Statistics, |
| 13 | } from '../types'; |
| 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 { |
| 24 | id: ChargingStationWorkerMessageEvents.started, |
| 25 | data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), |
| 26 | }; |
| 27 | } |
| 28 | |
| 29 | public static buildStoppedMessage( |
| 30 | chargingStation: ChargingStation |
| 31 | ): ChargingStationWorkerMessage<ChargingStationData> { |
| 32 | return { |
| 33 | id: ChargingStationWorkerMessageEvents.stopped, |
| 34 | data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | public static buildUpdatedMessage( |
| 39 | chargingStation: ChargingStation |
| 40 | ): ChargingStationWorkerMessage<ChargingStationData> { |
| 41 | return { |
| 42 | id: ChargingStationWorkerMessageEvents.updated, |
| 43 | data: MessageChannelUtils.buildChargingStationDataPayload(chargingStation), |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | public static buildPerformanceStatisticsMessage( |
| 48 | statistics: Statistics |
| 49 | ): ChargingStationWorkerMessage<Statistics> { |
| 50 | return { |
| 51 | id: ChargingStationWorkerMessageEvents.performanceStatistics, |
| 52 | data: statistics, |
| 53 | }; |
| 54 | } |
| 55 | |
| 56 | private static buildChargingStationDataPayload( |
| 57 | chargingStation: ChargingStation |
| 58 | ): ChargingStationData { |
| 59 | return { |
| 60 | started: chargingStation.started, |
| 61 | stationInfo: chargingStation.stationInfo, |
| 62 | connectors: buildConnectorsStatus(chargingStation), |
| 63 | evses: buildEvsesStatus(chargingStation, OutputFormat.worker), |
| 64 | ocppConfiguration: chargingStation.ocppConfiguration, |
| 65 | wsState: chargingStation?.wsConnection?.readyState, |
| 66 | bootNotificationResponse: chargingStation.bootNotificationResponse, |
| 67 | ...(chargingStation.automaticTransactionGenerator && { |
| 68 | automaticTransactionGenerator: |
| 69 | buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation), |
| 70 | }), |
| 71 | }; |
| 72 | } |
| 73 | } |