-
Notifications
You must be signed in to change notification settings - Fork 39
/
api.ts
174 lines (164 loc) · 4.45 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright (c) 2023 S44, LLC
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
import { ILogObj, Logger } from 'tslog';
import { ISmartChargingModuleApi } from './interface';
import { SmartChargingModule } from './module';
import {
AbstractModuleApi,
AsMessageEndpoint,
CallAction,
ClearChargingProfileRequest,
ClearChargingProfileRequestSchema,
ClearedChargingLimitRequestSchema,
CustomerInformationRequest,
GetChargingProfilesRequest,
GetChargingProfilesRequestSchema,
GetCompositeScheduleRequest,
GetCompositeScheduleRequestSchema,
IMessageConfirmation,
Namespace,
SetChargingProfileRequest,
SetChargingProfileRequestSchema,
} from '@citrineos/base';
import { FastifyInstance } from 'fastify';
/**
* Server API for the SmartCharging module.
*/
export class SmartChargingModuleApi
extends AbstractModuleApi<SmartChargingModule>
implements ISmartChargingModuleApi {
/**
* Constructs a new instance of the class.
*
* @param {SmartChargingModule} SmartChargingModule - The SmartCharging module.
* @param {FastifyInstance} server - The Fastify server instance.
* @param {Logger<ILogObj>} [logger] - The logger instance.
*/
constructor(
smartChargingModule: SmartChargingModule,
server: FastifyInstance,
logger?: Logger<ILogObj>,
) {
super(smartChargingModule, server, logger);
}
/**
* Message endpoints
*/
@AsMessageEndpoint(
CallAction.ClearChargingProfile,
ClearChargingProfileRequestSchema,
)
clearChargingProfile(
identifier: string,
tenantId: string,
request: ClearChargingProfileRequest,
callbackUrl?: string,
): Promise<IMessageConfirmation> {
return this._module.sendCall(
identifier,
tenantId,
CallAction.ClearChargingProfile,
request,
callbackUrl,
);
}
@AsMessageEndpoint(
CallAction.GetChargingProfiles,
GetChargingProfilesRequestSchema,
)
getChargingProfile(
identifier: string,
tenantId: string,
request: GetChargingProfilesRequest,
callbackUrl?: string,
): Promise<IMessageConfirmation> {
return this._module.sendCall(
identifier,
tenantId,
CallAction.GetChargingProfiles,
request,
callbackUrl,
);
}
@AsMessageEndpoint(
CallAction.SetChargingProfile,
SetChargingProfileRequestSchema,
)
setChargingProfile(
identifier: string,
tenantId: string,
request: SetChargingProfileRequest,
callbackUrl?: string,
): Promise<IMessageConfirmation> {
return this._module.sendCall(
identifier,
tenantId,
CallAction.SetChargingProfile,
request,
callbackUrl,
);
}
@AsMessageEndpoint(
CallAction.ClearedChargingLimit,
ClearedChargingLimitRequestSchema,
)
clearedChargingLimit(
identifier: string,
tenantId: string,
request: CustomerInformationRequest,
callbackUrl?: string,
): Promise<IMessageConfirmation> {
return this._module.sendCall(
identifier,
tenantId,
CallAction.ClearedChargingLimit,
request,
callbackUrl,
);
}
@AsMessageEndpoint(
CallAction.GetCompositeSchedule,
GetCompositeScheduleRequestSchema,
)
getCompositeSchedule(
identifier: string,
tenantId: string,
request: GetCompositeScheduleRequest,
callbackUrl?: string,
): Promise<IMessageConfirmation> {
return this._module.sendCall(
identifier,
tenantId,
CallAction.GetCompositeSchedule,
request,
callbackUrl,
);
}
/**
* Data endpoints
*/
/**
* Overrides superclass method to generate the URL path based on the input {@link CallAction} and the module's endpoint prefix configuration.
*
* @param {CallAction} input - The input {@link CallAction}.
* @return {string} - The generated URL path.
*/
protected _toMessagePath(input: CallAction): string {
const endpointPrefix =
this._module.config.modules.smartcharging?.endpointPrefix;
return super._toMessagePath(input, endpointPrefix);
}
/**
* Overrides superclass method to generate the URL path based on the input {@link Namespace} and the module's endpoint prefix configuration.
*
* @param {CallAction} input - The input {@link Namespace}.
* @return {string} - The generated URL path.
*/
protected _toDataPath(input: Namespace): string {
const endpointPrefix =
this._module.config.modules.smartcharging?.endpointPrefix;
return super._toDataPath(input, endpointPrefix);
}
}