Add Lexus vehicle support (#28836)
This commit is contained in:
parent
e647eadf3f
commit
1c8387c978
6 changed files with 52 additions and 16 deletions
26
templates/definition/vehicle/lexus.yaml
Normal file
26
templates/definition/vehicle/lexus.yaml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
template: lexus
|
||||||
|
products:
|
||||||
|
- brand: Lexus
|
||||||
|
requirements:
|
||||||
|
description:
|
||||||
|
de: |
|
||||||
|
Benötigt Lexus Link+ Connected Services Account.
|
||||||
|
en: |
|
||||||
|
Requires Lexus Link+ Connected Services Account.
|
||||||
|
params:
|
||||||
|
- preset: vehicle-common
|
||||||
|
- name: user
|
||||||
|
required: true
|
||||||
|
- name: password
|
||||||
|
required: true
|
||||||
|
- name: vin
|
||||||
|
example: JT...
|
||||||
|
- name: cache
|
||||||
|
default: 15m
|
||||||
|
render: |
|
||||||
|
type: lexus
|
||||||
|
{{ include "vehicle-common" . }}
|
||||||
|
user: {{ .user }}
|
||||||
|
password: {{ .password }}
|
||||||
|
vin: {{ .vin }}
|
||||||
|
cache: {{ .cache }}
|
||||||
|
|
@ -9,18 +9,23 @@ import (
|
||||||
"github.com/evcc-io/evcc/vehicle/toyota"
|
"github.com/evcc-io/evcc/vehicle/toyota"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Toyota is an api.Vehicle implementation for Toyota cars
|
// Toyota is an api.Vehicle implementation for Toyota/Lexus cars
|
||||||
type Toyota struct {
|
type Toyota struct {
|
||||||
*embed
|
*embed
|
||||||
*toyota.Provider
|
*toyota.Provider
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Add("toyota", NewToyotaFromConfig)
|
registry.Add("toyota", func(other map[string]any) (api.Vehicle, error) {
|
||||||
|
return newToyotaFromConfig("toyota", "T", other)
|
||||||
|
})
|
||||||
|
registry.Add("lexus", func(other map[string]any) (api.Vehicle, error) {
|
||||||
|
return newToyotaFromConfig("lexus", "L", other)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewToyotaFromConfig creates a new vehicle
|
// newToyotaFromConfig creates a new vehicle
|
||||||
func NewToyotaFromConfig(other map[string]any) (api.Vehicle, error) {
|
func newToyotaFromConfig(brand, brandCode string, other map[string]any) (api.Vehicle, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
embed `mapstructure:",squash"`
|
embed `mapstructure:",squash"`
|
||||||
User, Password, VIN string
|
User, Password, VIN string
|
||||||
|
|
@ -41,15 +46,15 @@ func NewToyotaFromConfig(other map[string]any) (api.Vehicle, error) {
|
||||||
embed: &cc.embed,
|
embed: &cc.embed,
|
||||||
}
|
}
|
||||||
|
|
||||||
log := util.NewLogger("toyota").Redact(cc.User, cc.Password, cc.VIN)
|
log := util.NewLogger(brand).Redact(cc.User, cc.Password, cc.VIN)
|
||||||
identity := toyota.NewIdentity(log)
|
identity := toyota.NewIdentity(log, brandCode)
|
||||||
|
|
||||||
err := identity.Login(cc.User, cc.Password)
|
err := identity.Login(cc.User, cc.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v, fmt.Errorf("login failed: %w", err)
|
return v, fmt.Errorf("login failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
api := toyota.NewAPI(log, identity)
|
api := toyota.NewAPI(log, identity, brandCode)
|
||||||
|
|
||||||
cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles)
|
cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ type API struct {
|
||||||
identity *Identity
|
identity *Identity
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAPI(log *util.Logger, identity *Identity) *API {
|
func NewAPI(log *util.Logger, identity *Identity, brandCode string) *API {
|
||||||
v := &API{
|
v := &API{
|
||||||
Helper: request.NewHelper(log),
|
Helper: request.NewHelper(log),
|
||||||
log: log,
|
log: log,
|
||||||
|
|
@ -57,6 +57,7 @@ func NewAPI(log *util.Logger, identity *Identity) *API {
|
||||||
"x-client-ref": clientRef,
|
"x-client-ref": clientRef,
|
||||||
"x-appversion": clientRefKey,
|
"x-appversion": clientRefKey,
|
||||||
"x-channel": channel,
|
"x-channel": channel,
|
||||||
|
"X-Appbrand": brandCode,
|
||||||
}),
|
}),
|
||||||
Base: &oauth2.Transport{
|
Base: &oauth2.Transport{
|
||||||
Source: identity,
|
Source: identity,
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ func TestAPI(t *testing.T) {
|
||||||
|
|
||||||
// Create and login identity
|
// Create and login identity
|
||||||
log := util.NewLogger("foo")
|
log := util.NewLogger("foo")
|
||||||
identity := NewIdentity(log)
|
identity := NewIdentity(log, "T")
|
||||||
err := identity.Login(user, password)
|
err := identity.Login(user, password)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Create API client
|
// Create API client
|
||||||
api := NewAPI(log, identity)
|
api := NewAPI(log, identity, "T")
|
||||||
|
|
||||||
// Test Vehicles method
|
// Test Vehicles method
|
||||||
vehicles, err := api.Vehicles()
|
vehicles, err := api.Vehicles()
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,15 @@ type Identity struct {
|
||||||
log *util.Logger
|
log *util.Logger
|
||||||
*request.Helper
|
*request.Helper
|
||||||
oauth2.TokenSource
|
oauth2.TokenSource
|
||||||
uuid string
|
uuid string
|
||||||
|
brandCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIdentity(log *util.Logger) *Identity {
|
func NewIdentity(log *util.Logger, brandCode string) *Identity {
|
||||||
return &Identity{
|
return &Identity{
|
||||||
log: log,
|
log: log,
|
||||||
Helper: request.NewHelper(log),
|
Helper: request.NewHelper(log),
|
||||||
|
brandCode: brandCode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +164,9 @@ func (v *Identity) refreshToken(token *oauth2.Token) (*oauth2.Token, error) {
|
||||||
func (v *Identity) Login(user, password string) error {
|
func (v *Identity) Login(user, password string) error {
|
||||||
uri := fmt.Sprintf("%s/%s", BaseUrl, AuthenticationPath)
|
uri := fmt.Sprintf("%s/%s", BaseUrl, AuthenticationPath)
|
||||||
req, err := request.New(http.MethodPost, uri, nil, map[string]string{
|
req, err := request.New(http.MethodPost, uri, nil, map[string]string{
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
|
"X-Brand": v.brandCode,
|
||||||
|
"X-Region": "EU",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create authentication request: %w", err)
|
return fmt.Errorf("failed to create authentication request: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestIdentityLogin(t *testing.T) {
|
||||||
|
|
||||||
util.LogLevel("trace", nil) // Enable trace logging
|
util.LogLevel("trace", nil) // Enable trace logging
|
||||||
log := util.NewLogger("test")
|
log := util.NewLogger("test")
|
||||||
identity := NewIdentity(log)
|
identity := NewIdentity(log, "T")
|
||||||
|
|
||||||
err := identity.Login(user, password)
|
err := identity.Login(user, password)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue