Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions internal/services/tesla_fleet_api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,39 @@ func (t *teslaFleetAPIService) GetTelemetrySubscriptionStatus(ctx context.Contex
}, nil
}

type TeslaOptionsResponse struct {
Codes []TeslaOptionCode `json:"codes"`
}

type TeslaOptionCode struct {
Code string `json:"code"`
DisplayName string `json:"displayName"`
IsActive bool `json:"isActive"`
}

// GetOptions returns a list of option codes for the vehicle with the given VIN.
// https://developer.tesla.com/docs/fleet-api/endpoints/vehicle-endpoints#options
func (t *teslaFleetAPIService) GetOptions(ctx context.Context, token, vin string) ([]TeslaOptionCode, error) {
u := t.FleetBase.JoinPath("api/1/dx/vehicles/options")

q := u.Query()
q.Set("vin", vin)
u.RawQuery = q.Encode()

body, err := t.performRequest(ctx, u, token, http.MethodGet, nil)
if err != nil {
return nil, err
}

var optionsResp TeslaResponseWrapper[TeslaOptionsResponse]
err = json.Unmarshal(body, &optionsResp)
if err != nil {
return nil, err
}

return optionsResp.Response.Codes, nil
}

var ErrUnauthorized = errors.New("unauthorized")

// performRequest a helper function for making http requests, it adds a timeout context and parses error response
Expand Down
Loading