Skip to content

Commit

Permalink
fix(states): pass the now-required endpoints option in Vehicle.Data
Browse files Browse the repository at this point in the history
The tesla API updated, requiring the endpoints parameter in vehicle_data to
return some types of information (like vehicle location). Add this parameter to
the request so that the existing API continues to function.
  • Loading branch information
pitust committed Dec 2, 2023
1 parent 2ca3c53 commit 05b10a3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion states.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"time"
"net/url"
)

// ChargeState contains the current charge states that exist within the vehicle.
Expand Down Expand Up @@ -309,7 +310,13 @@ func stateError(sr *VehicleData) error {
// A utility function to fetch the appropriate state of the vehicle
func (c *Client) fetchState(id int64) (*VehicleData, error) {
var res VehicleData
path := strings.Join([]string{c.baseURL, "vehicles", strconv.FormatInt(id, 10), "vehicle_data"}, "/")
endpoints := []string{"charge_state", "climate_state", "closures_state", "drive_state", "gui_settings", "location_data", "vehicle_config", "vehicle_state"}
path := strings.Join([]string{
c.baseURL,
"vehicles",
strconv.FormatInt(id, 10),
"vehicle_data?endpoints=" + url.QueryEscape(strings.Join(endpoints, ";")),
}, "/")
if err := c.getJSON(path, &res); err != nil {
return nil, err
}
Expand Down

0 comments on commit 05b10a3

Please sign in to comment.