UI Services: add status notification command
[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 constructor(uiServer: AbstractUIServer) {
13 super(uiServer, ProtocolVersion['0.0.1']);
14 this.requestHandlers.set(
15 ProcedureName.START_CHARGING_STATION,
16 this.handleStartChargingStation.bind(this) as ProtocolRequestHandler
17 );
18 this.requestHandlers.set(
19 ProcedureName.STOP_CHARGING_STATION,
20 this.handleStopChargingStation.bind(this) as ProtocolRequestHandler
21 );
22 this.requestHandlers.set(
23 ProcedureName.OPEN_CONNECTION,
24 this.handleOpenConnection.bind(this) as ProtocolRequestHandler
25 );
26 this.requestHandlers.set(
27 ProcedureName.CLOSE_CONNECTION,
28 this.handleCloseConnection.bind(this) as ProtocolRequestHandler
29 );
30 this.requestHandlers.set(
31 ProcedureName.START_TRANSACTION,
32 this.handleStartTransaction.bind(this) as ProtocolRequestHandler
33 );
34 this.requestHandlers.set(
35 ProcedureName.STOP_TRANSACTION,
36 this.handleStopTransaction.bind(this) as ProtocolRequestHandler
37 );
38 this.requestHandlers.set(
39 ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
40 this.handleStartAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler
41 );
42 this.requestHandlers.set(
43 ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
44 this.handleStopAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler
45 );
46 this.requestHandlers.set(
47 ProcedureName.STATUS_NOTIFICATION,
48 this.handleStatusNotification.bind(this) as ProtocolRequestHandler
49 );
50 }
51
52 private handleStartChargingStation(uuid: string, payload: RequestPayload): void {
53 this.sendBroadcastChannelRequest(
54 uuid,
55 BroadcastChannelProcedureName.START_CHARGING_STATION,
56 payload
57 );
58 }
59
60 private handleStopChargingStation(uuid: string, payload: RequestPayload): void {
61 this.sendBroadcastChannelRequest(
62 uuid,
63 BroadcastChannelProcedureName.STOP_CHARGING_STATION,
64 payload
65 );
66 }
67
68 private handleOpenConnection(uuid: string, payload: RequestPayload): void {
69 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.OPEN_CONNECTION, payload);
70 }
71
72 private handleCloseConnection(uuid: string, payload: RequestPayload): void {
73 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.CLOSE_CONNECTION, payload);
74 }
75
76 private handleStartTransaction(uuid: string, payload: RequestPayload): void {
77 this.sendBroadcastChannelRequest(
78 uuid,
79 BroadcastChannelProcedureName.START_TRANSACTION,
80 payload
81 );
82 }
83
84 private handleStopTransaction(uuid: string, payload: RequestPayload): void {
85 this.sendBroadcastChannelRequest(uuid, BroadcastChannelProcedureName.STOP_TRANSACTION, payload);
86 }
87
88 private handleStartAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
89 this.sendBroadcastChannelRequest(
90 uuid,
91 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
92 payload
93 );
94 }
95
96 private handleStopAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
97 this.sendBroadcastChannelRequest(
98 uuid,
99 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
100 payload
101 );
102 }
103
104 private handleStatusNotification(uuid: string, payload: RequestPayload): void {
105 this.sendBroadcastChannelRequest(
106 uuid,
107 BroadcastChannelProcedureName.STATUS_NOTIFICATION,
108 payload
109 );
110 }
111 }