1 import { CircularBuffer
} from
'mnemonist'
3 import type { ChargingStation
} from
'../charging-station/index.js'
6 type ChargingStationData
,
7 type ChargingStationWorkerMessage
,
8 ChargingStationWorkerMessageEvents
,
11 } from
'../types/index.js'
13 buildChargingStationAutomaticTransactionGeneratorConfiguration
,
14 buildConnectorsStatus
,
17 } from
'./ChargingStationConfigurationUtils.js'
19 export const buildAddedMessage
= (
20 chargingStation
: ChargingStation
21 ): ChargingStationWorkerMessage
<ChargingStationData
> => {
23 data
: buildChargingStationDataPayload(chargingStation
),
24 event
: ChargingStationWorkerMessageEvents
.added
,
28 export const buildDeletedMessage
= (
29 chargingStation
: ChargingStation
30 ): ChargingStationWorkerMessage
<ChargingStationData
> => {
32 data
: buildChargingStationDataPayload(chargingStation
),
33 event
: ChargingStationWorkerMessageEvents
.deleted
,
37 export const buildStartedMessage
= (
38 chargingStation
: ChargingStation
39 ): ChargingStationWorkerMessage
<ChargingStationData
> => {
41 data
: buildChargingStationDataPayload(chargingStation
),
42 event
: ChargingStationWorkerMessageEvents
.started
,
46 export const buildStoppedMessage
= (
47 chargingStation
: ChargingStation
48 ): ChargingStationWorkerMessage
<ChargingStationData
> => {
50 data
: buildChargingStationDataPayload(chargingStation
),
51 event
: ChargingStationWorkerMessageEvents
.stopped
,
55 export const buildUpdatedMessage
= (
56 chargingStation
: ChargingStation
57 ): ChargingStationWorkerMessage
<ChargingStationData
> => {
59 data
: buildChargingStationDataPayload(chargingStation
),
60 event
: ChargingStationWorkerMessageEvents
.updated
,
64 export const buildPerformanceStatisticsMessage
= (
65 statistics
: Statistics
66 ): ChargingStationWorkerMessage
<Statistics
> => {
67 const statisticsData
= [...statistics
.statisticsData
].map(([key
, value
]) => {
68 if (value
.measurementTimeSeries
instanceof CircularBuffer
) {
69 value
.measurementTimeSeries
= value
.measurementTimeSeries
.toArray() as TimestampedData
[]
75 createdAt
: statistics
.createdAt
,
77 name
: statistics
.name
,
79 updatedAt
: statistics
.updatedAt
,
82 event
: ChargingStationWorkerMessageEvents
.performanceStatistics
,
86 const buildChargingStationDataPayload
= (chargingStation
: ChargingStation
): ChargingStationData
=> {
88 bootNotificationResponse
: chargingStation
.bootNotificationResponse
,
89 connectors
: buildConnectorsStatus(chargingStation
),
90 evses
: buildEvsesStatus(chargingStation
, OutputFormat
.worker
),
91 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92 ocppConfiguration
: chargingStation
.ocppConfiguration
!,
93 started
: chargingStation
.started
,
94 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
95 stationInfo
: chargingStation
.stationInfo
!,
96 supervisionUrl
: chargingStation
.wsConnectionUrl
.href
,
97 wsState
: chargingStation
.wsConnection
?.readyState
,
98 ...(chargingStation
.automaticTransactionGenerator
!= null && {
99 automaticTransactionGenerator
:
100 buildChargingStationAutomaticTransactionGeneratorConfiguration(chargingStation
),