forked from evcc-io/evcc
/
types.go
71 lines (63 loc) · 1.25 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
package ford
import (
"strings"
"time"
)
type VehiclesResponse struct {
UserVehicles struct {
VehicleDetails []struct {
VIN string
}
}
}
// StatusResponse is the response to the vehicle status request
type StatusResponse struct {
VehicleStatus struct {
BatteryFillLevel struct {
Value float64
Timestamp Timestamp
}
ElVehDTE struct {
Value float64
Timestamp Timestamp
}
ChargingStatus struct {
Value string
Timestamp Timestamp
}
ChargeEndTime struct {
Value Timestamp
Timestamp Timestamp
}
PlugStatus struct {
Value int
Timestamp Timestamp
}
Odometer struct {
Value float64
Timestamp Timestamp
}
Gps struct {
Latitude float64 `json:",string"`
Longitude float64 `json:",string"`
GpsState string
Timestamp Timestamp
}
LastRefresh Timestamp
}
Status int
}
const TimeFormat = "01-02-2006 15:04:05" // time format used by Ford API, time is in UTC
// Timestamp implements JSON unmarshal
type Timestamp struct {
time.Time
}
// UnmarshalJSON decodes string timestamp into time.Time
func (ct *Timestamp) UnmarshalJSON(data []byte) error {
s := strings.Trim(string(data), "\"")
t, err := time.Parse(TimeFormat, s)
if err == nil {
(*ct).Time = t
}
return err
}