-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchargingsites.go
54 lines (47 loc) · 1.52 KB
/
chargingsites.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
package tesla
import (
"fmt"
"net/http"
)
// ChargingSites represents nearby Tesla-operated charging stations.
type ChargingSites struct {
CongestionSyncTimeUtcSecs int `json:"congestion_sync_time_utc_secs"`
DestinationCharging []struct {
Location struct {
Lat float64 `json:"lat"`
Long float64 `json:"long"`
} `json:"location"`
Name string `json:"name"`
Type string `json:"type"`
DistanceMiles float64 `json:"distance_miles"`
} `json:"destination_charging"`
Superchargers []struct {
Location struct {
Lat float64 `json:"lat"`
Long float64 `json:"long"`
} `json:"location"`
Name string `json:"name"`
Type string `json:"type"`
DistanceMiles float64 `json:"distance_miles"`
AvailableStalls int `json:"available_stalls"`
TotalStalls int `json:"total_stalls"`
SiteClosed bool `json:"site_closed"`
} `json:"superchargers"`
Timestamp int64 `json:"timestamp"`
}
// GetNearbyChargingSites returns a list of nearby Tesla-operated charging stations. (Requires car
// software version 2018.48 or higher.)
func (c *Conn) GetNearbyChargingSites(id int) (*ChargingSites, error) {
if c.accessToken == "" {
return nil, fmt.Errorf("%w", ErrMissingAccessToken)
}
type response struct {
Response ChargingSites `json:"response"`
}
var respBody response
err := c.doRequest(http.MethodGet, fmt.Sprintf("/api/1/vehicles/%d/nearby_charging_sites", id), nil, &respBody)
if err != nil {
return nil, err
}
return &respBody.Response, nil
}