Skip to content

Commit

Permalink
Tesla: expose client id (#17821)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Dec 19, 2024
1 parent e33a682 commit fbd22d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions templates/definition/vehicle/tesla.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ requirements:
evcc: ["sponsorship"]
params:
- preset: vehicle-common
- name: clientId
advanced: true
- name: accessToken
required: true
mask: true
Expand All @@ -36,6 +38,8 @@ params:
render: |
type: tesla
vin: {{ .vin }}
credentials:
id: {{ .clientId }}
tokens:
access: {{ .accessToken }}
refresh: {{ .refreshToken }}
Expand Down
9 changes: 9 additions & 0 deletions vehicle/tesla.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
func NewTeslaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
Credentials ClientCredentials
Tokens Tokens
VIN string
CommandProxy string
Expand All @@ -53,6 +54,14 @@ func NewTeslaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}

if cc.Credentials.ID != "" {
tesla.OAuth2Config.ClientID = cc.Credentials.ID
}

if cc.Credentials.Secret != "" {
tesla.OAuth2Config.ClientSecret = cc.Credentials.Secret
}

token, err := cc.Tokens.Token()
if err != nil {
return nil, err
Expand Down

0 comments on commit fbd22d1

Please sign in to comment.