UI protocol: update Insomnia requests collection
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIService001.ts
1 import {
2 ProcedureName,
3 ProtocolRequestHandler,
4 ProtocolVersion,
5 RequestPayload,
6 } from '../../../types/UIProtocol';
7 import { BroadcastChannelProcedureName } from '../../../types/WorkerBroadcastChannel';
8 import type { AbstractUIServer } from '../AbstractUIServer';
9 import AbstractUIService from './AbstractUIService';
10
11 export default class UIService001 extends AbstractUIService {
12 private static readonly ProcedureNameToBroadCastChannelProcedureNameMap: Omit<
13 Record<ProcedureName, BroadcastChannelProcedureName>,
14 'startSimulator' | 'stopSimulator' | 'listChargingStations'
15 > = {
16 [ProcedureName.START_CHARGING_STATION]: BroadcastChannelProcedureName.START_CHARGING_STATION,
17 [ProcedureName.STOP_CHARGING_STATION]: BroadcastChannelProcedureName.STOP_CHARGING_STATION,
18 [ProcedureName.CLOSE_CONNECTION]: BroadcastChannelProcedureName.CLOSE_CONNECTION,
19 [ProcedureName.OPEN_CONNECTION]: BroadcastChannelProcedureName.OPEN_CONNECTION,
20 [ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR]:
21 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
22 [ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR]:
23 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
24 [ProcedureName.START_TRANSACTION]: BroadcastChannelProcedureName.START_TRANSACTION,
25 [ProcedureName.STOP_TRANSACTION]: BroadcastChannelProcedureName.STOP_TRANSACTION,
26 [ProcedureName.AUTHORIZE]: BroadcastChannelProcedureName.AUTHORIZE,
27 [ProcedureName.STATUS_NOTIFICATION]: BroadcastChannelProcedureName.STATUS_NOTIFICATION,
28 [ProcedureName.HEARTBEAT]: BroadcastChannelProcedureName.HEARTBEAT,
29 [ProcedureName.METER_VALUES]: BroadcastChannelProcedureName.METER_VALUES,
30 };
31
32 constructor(uiServer: AbstractUIServer) {
33 super(uiServer, ProtocolVersion['0.0.1']);
34 this.requestHandlers.set(
35 ProcedureName.START_CHARGING_STATION,
36 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
37 );
38 this.requestHandlers.set(
39 ProcedureName.STOP_CHARGING_STATION,
40 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
41 );
42 this.requestHandlers.set(
43 ProcedureName.OPEN_CONNECTION,
44 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
45 );
46 this.requestHandlers.set(
47 ProcedureName.CLOSE_CONNECTION,
48 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
49 );
50 this.requestHandlers.set(
51 ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
52 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
53 );
54 this.requestHandlers.set(
55 ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
56 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
57 );
58 this.requestHandlers.set(
59 ProcedureName.START_TRANSACTION,
60 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
61 );
62 this.requestHandlers.set(
63 ProcedureName.STOP_TRANSACTION,
64 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
65 );
66 this.requestHandlers.set(
67 ProcedureName.AUTHORIZE,
68 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
69 );
70 this.requestHandlers.set(
71 ProcedureName.STATUS_NOTIFICATION,
72 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
73 );
74 this.requestHandlers.set(
75 ProcedureName.HEARTBEAT,
76 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
77 );
78 this.requestHandlers.set(
79 ProcedureName.METER_VALUES,
80 this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
81 );
82 }
83
84 private handleProtocolRequest(
85 uuid: string,
86 procedureName: ProcedureName,
87 payload: RequestPayload
88 ): void {
89 this.sendBroadcastChannelRequest(
90 uuid,
91 UIService001.ProcedureNameToBroadCastChannelProcedureNameMap[
92 procedureName
93 ] as BroadcastChannelProcedureName,
94 payload
95 );
96 }
97 }