-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.go
284 lines (232 loc) · 7.06 KB
/
models.go
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package mercedes
import (
"encoding/json"
"errors"
)
type Vehicle struct {
Id string `json:"id"`
LicensePlate string `json:"licenseplate"`
VIN string `json:"finorvin"`
}
type VehicleDetail struct {
Id string `json:"id"`
LicensePlate string `json:"licenseplate"`
SalesDesignation string `json:"salesdesignation"`
VIN string `json:"finorvin"`
ModelYear string `json:"modelyear"`
ColorName string `json:"colorname"`
FuelType string `json:"fueltype"`
PowerHP string `json:"powerhp"`
PowerKW string `json:"powerkw"`
NumberOfDoors string `json:"numberofdoors"`
NumberOfSeats string `json:"numberofseats"`
}
type RetrievalStatus string
const (
Valid RetrievalStatus = "VALID"
Initialized = "INITIALIZED"
Invalid = "INVALID"
NotSupported = "NOT_SUPPORTED"
)
func (rs *RetrievalStatus) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type RS RetrievalStatus
var r = (*RS)(rs)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *rs {
case Valid, Initialized, Invalid, NotSupported:
return nil
}
return errors.New("invalid retrieval status")
}
type PressureUnit string
const (
KiloPascal PressureUnit = "KILOPASCAL"
)
func (pu *PressureUnit) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type PU PressureUnit
var r = (*PU)(pu)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *pu {
case KiloPascal:
return nil
}
return errors.New("invalid pressure unit")
}
type TirePressureStatus struct {
Unit PressureUnit `json:"unit"`
Value float64 `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type Tires struct {
TirePressureFrontLeft TirePressureStatus `json:"tirepressurefrontleft"`
TirePressureFrontRight TirePressureStatus `json:"tirepressurefrontright"`
TirePressureRearLeft TirePressureStatus `json:"tirepressurerearleft"`
TirePressureRearRight TirePressureStatus `json:"tirepressurerearright"`
}
type DoorState string
const (
Open DoorState = "OPEN"
Closed = "CLOSED"
)
func (ds *DoorState) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type DS DoorState
var r = (*DS)(ds)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *ds {
case Open, Closed:
return nil
}
return errors.New("invalid door state")
}
type DoorOpenStatus struct {
Value DoorState `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type DoorLockState string
const (
Locked DoorLockState = "LOCKED"
Unlocked = "UNLOCKED"
)
func (ds *DoorLockState) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type DS DoorLockState
var r = (*DS)(ds)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *ds {
case Locked, Unlocked:
return nil
}
return errors.New("invalid door lock state")
}
type DoorLockStatus struct {
Value DoorLockState `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type Doors struct {
DoorStatusFrontLeft DoorOpenStatus `json:"doorstatusfrontleft"`
DoorStatusFrontRight DoorOpenStatus `json:"doorstatusfrontright"`
DoorStatusRearLeft DoorOpenStatus `json:"doorstatusrearleft"`
DoorStatusRearRight DoorOpenStatus `json:"doorstatusrearright"`
DoorLockStatusFrontLeft DoorLockStatus `json:"doorlockstatusfrontleft"`
DoorLockStatusFrontRight DoorLockStatus `json:"doorlockstatusfrontright"`
DoorLockStatusRearLeft DoorLockStatus `json:"doorlockstatusrearleft"`
DoorLockStatusRearRight DoorLockStatus `json:"doorlockstatusrearright"`
DoorLockStatusDeckLid DoorLockStatus `json:"doorlockstatusdecklid"`
DoorLockStatusGas DoorLockStatus `json:"doorlockstatusgas"`
DoorLockStatusVehicle DoorLockStatus `json:"doorlockstatusvehicle"`
}
type DoorLockCommand string
const (
Lock DoorLockCommand = "LOCK"
Unlock = "UNLOCK"
)
func (dl *DoorLockCommand) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type DL DoorLockCommand
var r = (*DL)(dl)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *dl {
case Lock, Unlock:
return nil
}
return errors.New("invalid door lock/unlock command")
}
type DoorLockChangeRequestBody struct {
Command DoorLockCommand `json:"command"`
}
type LocationCoordinate struct {
Value float64 `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type Location struct {
Latitude LocationCoordinate `json:"latitude"`
Longitude LocationCoordinate `json:"longitude"`
Heading LocationCoordinate `json:"heading"`
}
type DistanceUnit string
const (
Kilometers DistanceUnit = "KILOMETERS"
)
func (du *DistanceUnit) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type DU DistanceUnit
var r = (*DU)(du)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *du {
case Kilometers:
return nil
}
return errors.New("invalid distance unit")
}
type DistanceDriven struct {
Unit DistanceUnit `json:"unit"`
Value int `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type DistanceDrivenResponse struct {
Odometer DistanceDriven `json:"odometer"`
DistanceSinceReset DistanceDriven `json:"distancesincereset"`
DistanceSinceStart DistanceDriven `json:"distancesincestart"`
}
type PercentUnit string
const (
Percent PercentUnit = "PERCENT"
)
func (pu *PercentUnit) UnmarshalJSON(b []byte) error {
// Define a secondary type to avoid ending up with a recursive call to json.Unmarshal
type PU PercentUnit
var r = (*PU)(pu)
err := json.Unmarshal(b, &r)
if err != nil {
return err
}
switch *pu {
case Percent:
return nil
}
return errors.New("invalid percent unit")
}
type FuelLevel struct {
Unit PercentUnit `json:"unit"`
Value int `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type FuelLevelResponse struct {
FuelLevelPercent FuelLevel `json:"fuellevelpercent"`
}
type StateOfCharge struct {
Unit PercentUnit `json:"unit"`
Value int `json:"value"`
RetrievalStatus RetrievalStatus `json:"retrievalstatus"`
Timestamp int64 `json:"timestamp"`
}
type StateOfChargeResponse struct {
StateOfCharge StateOfCharge `json:"stateofcharge"`
}