forked from evcc-io/evcc
/
types.go
87 lines (72 loc) · 1.49 KB
/
types.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
package jlr
import (
"strconv"
"github.com/connectorjs/evcm/api"
"golang.org/x/oauth2"
)
type Token struct {
AuthToken string `json:"authorization_token"`
ExpiresIn int `json:"expires_in,string"`
oauth2.Token
}
type User struct {
HomeMarket string `json:"homeMarket"`
UserId string `json:"userId"`
}
type Vehicle struct {
UserId string `json:"userId"`
VIN string `json:"vin"`
Role string `json:"role"`
}
type VehiclesResponse struct {
Vehicles []Vehicle
}
type KeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
}
type KeyValueList []KeyValue
type StatusResponse struct {
VehicleStatus struct {
CoreStatus KeyValueList
EvStatus KeyValueList
}
}
type PositionResponse struct {
Position struct {
Latitude float64
Longitude float64
Timestamp string
Speed float64
Heading float64
PositionQuality interface{}
}
}
type PinResponse struct {
Token string
}
type ActionResponse struct {
FailureDescription string
}
func (l KeyValueList) StringVal(key string) (string, error) {
for _, el := range l {
if el.Key == key {
return el.Value, nil
}
}
return "", api.ErrNotAvailable
}
func (l KeyValueList) FloatVal(key string) (float64, error) {
s, err := l.StringVal(key)
if err != nil {
return 0, err
}
return strconv.ParseFloat(s, 64)
}
func (l KeyValueList) IntVal(key string) (int64, error) {
s, err := l.StringVal(key)
if err != nil {
return 0, err
}
return strconv.ParseInt(s, 10, 64)
}