Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skoda: fix retrieving list of vehicles #9698

Merged
merged 2 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions vehicle/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ type embed struct {
OnIdentify api.ActionConfig `mapstructure:"onIdentify"`
}

// Title implements the api.Vehicle interface
func (v *embed) fromVehicle(title string, capacity float64) {
if v.Title_ == "" {
v.Title_ = title
}
if v.Capacity_ == 0 {
v.Capacity_ = capacity
}
}

// Title implements the api.Vehicle interface
func (v *embed) Title() string {
return v.Title_
Expand Down
9 changes: 3 additions & 6 deletions vehicle/skoda-enyaq.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewEnyaqFromConfig(other map[string]interface{}) (api.Vehicle, error) {
var err error
log := util.NewLogger("enyaq").Redact(cc.User, cc.Password, cc.VIN)

// use Skoda credentials to resolve list of vehicles
// use Skoda api to resolve list of vehicles
ts, err := service.TokenRefreshServiceTokenSource(log, skoda.TRSParams, skoda.AuthParams, cc.User, cc.Password)
if err != nil {
return nil, err
Expand All @@ -66,11 +66,8 @@ func NewEnyaqFromConfig(other map[string]interface{}) (api.Vehicle, error) {
},
)

if v.Title_ == "" {
v.Title_ = vehicle.Name
}
if v.Capacity_ == 0 {
v.Capacity_ = float64(vehicle.Specification.Battery.CapacityInKWh)
if err == nil {
v.fromVehicle(vehicle.Name, float64(vehicle.Specification.Battery.CapacityInKWh))
}

// use Connect credentials to build provider
Expand Down
30 changes: 24 additions & 6 deletions vehicle/skoda.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,38 @@ func NewSkodaFromConfig(other map[string]interface{}) (api.Vehicle, error) {

log := util.NewLogger("skoda").Redact(cc.User, cc.Password, cc.VIN)

trs := tokenrefreshservice.New(log, skoda.TRSParams)
ts, err := service.MbbTokenSource(log, trs, skoda.AuthClientID, skoda.AuthParams, cc.User, cc.Password)
// use Skoda api to resolve list of vehicles
ts, err := service.TokenRefreshServiceTokenSource(log, skoda.TRSParams, skoda.AuthParams, cc.User, cc.Password)
if err != nil {
return nil, err
}

api := vw.NewAPI(log, ts, skoda.Brand, skoda.Country)
api := skoda.NewAPI(log, ts)
api.Client.Timeout = cc.Timeout

cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles)
vehicle, err := ensureVehicleEx(
cc.VIN, api.Vehicles,
func(v skoda.Vehicle) string {
return v.VIN
},
)

if err == nil {
if err = api.HomeRegion(cc.VIN); err == nil {
v.Provider = vw.NewProvider(api, cc.VIN, cc.Cache)
v.fromVehicle(vehicle.Name, float64(vehicle.Specification.Battery.CapacityInKWh))
}

if err == nil {
trs := tokenrefreshservice.New(log, skoda.TRSParams)
ts, err := service.MbbTokenSource(log, trs, skoda.AuthClientID, skoda.AuthParams, cc.User, cc.Password)
if err != nil {
return nil, err
}

api := vw.NewAPI(log, ts, skoda.Brand, skoda.Country)
api.Client.Timeout = cc.Timeout

if err = api.HomeRegion(vehicle.VIN); err == nil {
v.Provider = vw.NewProvider(api, vehicle.VIN, cc.Cache)
}
}

Expand Down