-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdrivestate.go
42 lines (35 loc) · 1.3 KB
/
drivestate.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
package tesla
import (
"fmt"
"net/http"
)
// DriveState is the current state of driving for the vehicle.
type DriveState struct {
GpsAsOf int `json:"gps_as_of"`
Heading int `json:"heading"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
NativeLatitude float64 `json:"native_latitude"`
NativeLocationSupported int `json:"native_location_supported"`
NativeLongitude float64 `json:"native_longitude"`
NativeType string `json:"native_type"`
Power int `json:"power"`
ShiftState interface{} `json:"shift_state"`
Speed interface{} `json:"speed"`
Timestamp int64 `json:"timestamp"`
}
// GetDriveState retrieves the driving and position state of the vehicle.
func (c *Conn) GetDriveState(id int) (*DriveState, error) {
if c.accessToken == "" {
return nil, fmt.Errorf("%w", ErrMissingAccessToken)
}
type response struct {
Response DriveState `json:"response"`
}
var respBody response
err := c.doRequest(http.MethodGet, fmt.Sprintf("/api/1/vehicles/%d/data_request/drive_state", id), nil, &respBody)
if err != nil {
return nil, err
}
return &respBody.Response, nil
}