forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
101 lines (87 loc) · 1.83 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package fiat
import (
"fmt"
"html"
"strconv"
"time"
)
type ErrorInfo struct {
ErrorCode int
ErrorMessage string
ErrorDetails string
}
func (e ErrorInfo) Error() error {
if e.ErrorCode == 0 {
return nil
}
return fmt.Errorf("%s: %s", e.ErrorMessage, html.UnescapeString(e.ErrorDetails))
}
type VehiclesResponse struct {
Vehicles []Vehicle
}
type Vehicle struct {
VIN string
}
type StatusResponse struct {
VehicleInfo struct {
Odometer struct {
Odometer struct {
Value int `json:",string"`
Unit string
}
}
Timestamp TimeMillis
}
EvInfo *struct {
Battery struct {
ChargingLevel string // LEVEL_2
ChargingStatus string // CHARGING
DistanceToEmpty struct {
Value int
Unit string
}
PlugInStatus bool // true
StateOfCharge float64 // 75
TimeToFullyChargeL1 int // 0
TimeToFullyChargeL2 int // 540
TotalRange int // 17
}
Timestamp TimeMillis
} `json:",omitempty"`
Timestamp TimeMillis
}
type LocationResponse struct {
TimeStamp TimeMillis
Longitude float64
Latitude float64
Altitude float64
Bearing float64
IsLocationApprox bool
}
type ActionResponse struct {
Name, Message string
// deep refresh
Command string
CorrelationId string
ResponseStatus string
StatusTimestamp TimeMillis
AsyncRespTimeout int
}
type PinAuthResponse struct {
Name, Message string
Token string
Expiry int64 // ms duration
}
// TimeMillis implements JSON unmarshal for Unix timestamps in milliseconds
type TimeMillis struct {
time.Time
}
// UnmarshalJSON decodes unix timestamps in ms into time.Time
func (ct *TimeMillis) UnmarshalJSON(data []byte) error {
i, err := strconv.ParseInt(string(data), 10, 64)
if err == nil {
t := time.Unix(0, i*1e6)
ct.Time = t
}
return err
}