}
private readonly workerEventAdded = (data: ChargingStationData): void => {
- this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ this.uiServer.setChargingStationData(data.stationInfo.hashId, data)
logger.info(
`${this.logPrefix()} ${moduleName}.workerEventAdded: Charging station ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
private readonly workerEventDeleted = (data: ChargingStationData): void => {
- this.uiServer.chargingStations.delete(data.stationInfo.hashId)
+ this.uiServer.deleteChargingStationData(data.stationInfo.hashId)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const templateStatistics = this.templateStatistics.get(data.stationInfo.templateName)!
--templateStatistics.added
}
private readonly workerEventStarted = (data: ChargingStationData): void => {
- this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ this.uiServer.setChargingStationData(data.stationInfo.hashId, data)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
++this.templateStatistics.get(data.stationInfo.templateName)!.started
logger.info(
}
private readonly workerEventStopped = (data: ChargingStationData): void => {
- this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ this.uiServer.setChargingStationData(data.stationInfo.hashId, data)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
--this.templateStatistics.get(data.stationInfo.templateName)!.started
logger.info(
}
private readonly workerEventUpdated = (data: ChargingStationData): void => {
- this.uiServer.chargingStations.set(data.stationInfo.hashId, data)
+ this.uiServer.setChargingStationData(data.stationInfo.hashId, data)
}
}
const moduleName = 'AbstractUIServer'
export abstract class AbstractUIServer {
- public readonly chargingStations: Map<string, ChargingStationData>
public readonly chargingStationTemplates: Set<string>
-
protected readonly httpServer: Http2Server | Server
+
protected readonly responseHandlers: Map<
`${string}-${string}-${string}-${string}-${string}`,
ServerResponse | WebSocket
protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>
+ private readonly chargingStations: Map<string, ChargingStationData>
+
public constructor (protected readonly uiServerConfiguration: UIServerConfiguration) {
this.chargingStations = new Map<string, ChargingStationData>()
this.chargingStationTemplates = new Set<string>()
this.chargingStationTemplates.clear()
}
+ public deleteChargingStationData (hashId: string): boolean {
+ return this.chargingStations.delete(hashId)
+ }
+
+ public getChargingStationData (hashId: string): ChargingStationData | undefined {
+ return this.chargingStations.get(hashId)
+ }
+
+ public getChargingStationsCount (): number {
+ return this.chargingStations.size
+ }
+
+ public hasChargingStationData (hashId: string): boolean {
+ return this.chargingStations.has(hashId)
+ }
+
public hasResponseHandler (uuid: `${string}-${string}-${string}-${string}-${string}`): boolean {
return this.responseHandlers.has(uuid)
}
+ public listChargingStationData (): ChargingStationData[] {
+ return [...this.chargingStations.values()]
+ }
+
public abstract logPrefix (moduleName?: string, methodName?: string, prefixSuffix?: string): string
public async sendInternalRequest (request: ProtocolRequest): Promise<ProtocolResponse> {
public abstract sendResponse (response: ProtocolResponse): void
+ public setChargingStationData (hashId: string, data: ChargingStationData): void {
+ const cachedData = this.chargingStations.get(hashId)
+ if (cachedData == null || data.timestamp >= cachedData.timestamp) {
+ this.chargingStations.set(hashId, data)
+ }
+ }
+
public abstract start (): void
public stop (): void {
private handleListChargingStations (): ResponsePayload {
return {
- chargingStations: [...this.uiServer.chargingStations.values()] as JsonType[],
+ chargingStations: this.uiServer.listChargingStationData() as JsonType[],
status: ResponseStatus.SUCCESS,
} satisfies ResponsePayload
}
if (isNotEmptyArray(payload.hashIds)) {
payload.hashIds = payload.hashIds
.map(hashId => {
- if (this.uiServer.chargingStations.has(hashId)) {
+ if (this.uiServer.hasChargingStationData(hashId)) {
return hashId
}
logger.warn(
}
const expectedNumberOfResponses = Array.isArray(payload.hashIds)
? payload.hashIds.length
- : this.uiServer.chargingStations.size
+ : this.uiServer.getChargingStationsCount()
if (expectedNumberOfResponses === 0) {
throw new BaseError(
'hashIds array in the request payload does not contain any valid charging station hashId'
started: boolean
stationInfo: ChargingStationInfo
supervisionUrl: string
+ timestamp: number
wsState?:
| typeof WebSocket.CLOSED
| typeof WebSocket.CLOSING
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
stationInfo: chargingStation.stationInfo!,
supervisionUrl: chargingStation.wsConnectionUrl.href,
+ timestamp: Date.now(),
wsState: chargingStation.wsConnection?.readyState,
...(chargingStation.automaticTransactionGenerator != null && {
automaticTransactionGenerator: