From cf1234a6a618c4f09432115ff1ef7084066da931 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 3 Jul 2023 09:45:03 +0200 Subject: [PATCH] Remove dedicated Audi type, replace with eTron (#8547) (BC) --- templates/definition/vehicle/audi-etron.yaml | 14 --- templates/definition/vehicle/audi.yaml | 3 +- templates/docs/vehicle/audi_0.yaml | 1 - templates/docs/vehicle/etron_0.yaml | 30 ------- vehicle/audi-etron.go | 95 -------------------- vehicle/audi.go | 46 +++++++--- 6 files changed, 36 insertions(+), 153 deletions(-) delete mode 100644 templates/definition/vehicle/audi-etron.yaml delete mode 100644 templates/docs/vehicle/etron_0.yaml delete mode 100644 vehicle/audi-etron.go diff --git a/templates/definition/vehicle/audi-etron.yaml b/templates/definition/vehicle/audi-etron.yaml deleted file mode 100644 index f4dc36b6c..000000000 --- a/templates/definition/vehicle/audi-etron.yaml +++ /dev/null @@ -1,14 +0,0 @@ -template: etron -products: - - brand: Audi - description: - generic: e-tron -params: - - preset: vehicle-base - - preset: vehicle-identify - - name: vin - example: WAUZZZ... -render: | - type: etron - {{ include "vehicle-base" . }} - {{ include "vehicle-identify" . }} diff --git a/templates/definition/vehicle/audi.yaml b/templates/definition/vehicle/audi.yaml index ca8895d7c..fa0c4509e 100644 --- a/templates/definition/vehicle/audi.yaml +++ b/templates/definition/vehicle/audi.yaml @@ -1,8 +1,7 @@ template: audi +covers: ["etron"] products: - brand: Audi - description: - generic: legacy params: - preset: vehicle-base - preset: vehicle-identify diff --git a/templates/docs/vehicle/audi_0.yaml b/templates/docs/vehicle/audi_0.yaml index b364eb141..f81d2f259 100644 --- a/templates/docs/vehicle/audi_0.yaml +++ b/templates/docs/vehicle/audi_0.yaml @@ -1,6 +1,5 @@ product: brand: Audi - description: legacy render: - default: | type: template diff --git a/templates/docs/vehicle/etron_0.yaml b/templates/docs/vehicle/etron_0.yaml deleted file mode 100644 index 8a7b4bcaa..000000000 --- a/templates/docs/vehicle/etron_0.yaml +++ /dev/null @@ -1,30 +0,0 @@ -product: - brand: Audi - description: e-tron -render: - - default: | - type: template - template: etron - title: # Wird in der Benutzeroberfläche angezeigt (Optional) - user: # Benutzerkonto (bspw. E-Mail Adresse, User Id, etc.) - password: # Passwort des Benutzerkontos (bei führenden Nullen bitte in einfache Hochkommata setzen) - vin: WAUZZZ... # Erforderlich, wenn mehrere Fahrzeuge des Herstellers vorhanden sind (Optional) - capacity: 50 # Akkukapazität in kWh (Optional) - advanced: | - type: template - template: etron - title: # Wird in der Benutzeroberfläche angezeigt (Optional) - user: # Benutzerkonto (bspw. E-Mail Adresse, User Id, etc.) - password: # Passwort des Benutzerkontos (bei führenden Nullen bitte in einfache Hochkommata setzen) - vin: WAUZZZ... # Erforderlich, wenn mehrere Fahrzeuge des Herstellers vorhanden sind (Optional) - capacity: 50 # Akkukapazität in kWh (Optional) - phases: 3 # Die maximale Anzahl der Phasen welche genutzt werden können (Optional) - icon: car # Icon in der Benutzeroberfläche (Optional) - cache: 15m # Zeitintervall nach dem Daten erneut vom Fahrzeug abgefragt werden (Optional) - mode: # Möglich sind Off, Now, MinPV und PV, oder leer wenn keiner definiert werden soll (Optional) - minSoc: 25 # Ladung mit maximaler Geschwindigkeit bis zu dem angegeben Ladestand unabhängig PV-Erzeugung, wenn der Lademodus nicht auf 'Aus' steht (Optional) - targetSoc: 80 # Bis zu welchem Ladestand (Soc) soll das Fahrzeug geladen werden (Optional) - minCurrent: 6 # Definiert die minimale Stromstärke pro angeschlossener Phase mit welcher das Fahrzeug geladen werden soll (Optional) - maxCurrent: 16 # Definiert die maximale Stromstärke pro angeschlossener Phase mit welcher das Fahrzeug geladen werden soll (Optional) - identifiers: # Kann meist erst später eingetragen werden, siehe: https://docs.evcc.io/docs/guides/vehicles/#erkennung-des-fahrzeugs-an-der-wallbox (Optional) - priority: # Priorität des Ladepunktes oder Fahrzeugs in Relation zu anderen Ladepunkten oder Fahrzeugen für die Zuweisung von PV-Energie (Optional) diff --git a/vehicle/audi-etron.go b/vehicle/audi-etron.go deleted file mode 100644 index debc8b65b..000000000 --- a/vehicle/audi-etron.go +++ /dev/null @@ -1,95 +0,0 @@ -package vehicle - -import ( - "context" - "time" - - "github.com/evcc-io/evcc/api" - "github.com/evcc-io/evcc/util" - "github.com/evcc-io/evcc/util/request" - "github.com/evcc-io/evcc/vehicle/audi/etron" - "github.com/evcc-io/evcc/vehicle/vag/idkproxy" - "github.com/evcc-io/evcc/vehicle/vag/service" - "github.com/evcc-io/evcc/vehicle/vag/vwidentity" - "github.com/evcc-io/evcc/vehicle/vw/id" -) - -// https://github.com/TA2k/ioBroker.vw-connect -// https://github.com/arjenvrh/audi_connect_ha/blob/master/custom_components/audiconnect/audi_services.py - -// Etron is an api.Vehicle implementation for Audi eTron cars -type Etron struct { - *embed - *id.Provider // provides the api implementations -} - -func init() { - registry.Add("etron", NewEtronFromConfig) -} - -// NewEtronFromConfig creates a new vehicle -func NewEtronFromConfig(other map[string]interface{}) (api.Vehicle, error) { - cc := struct { - embed `mapstructure:",squash"` - User, Password, VIN string - Cache time.Duration - Timeout time.Duration - }{ - Cache: interval, - Timeout: request.Timeout, - } - - if err := util.DecodeOther(other, &cc); err != nil { - return nil, err - } - - if cc.User == "" || cc.Password == "" { - return nil, api.ErrMissingCredentials - } - - v := &Etron{ - embed: &cc.embed, - } - - log := util.NewLogger("etron").Redact(cc.User, cc.Password, cc.VIN) - - // get initial VW identity id_token - q, err := vwidentity.Login(log, etron.AuthParams, cc.User, cc.Password) - if err != nil { - return nil, err - } - - // exchange initial VW identity id_token for Audi AAZS token - idk := idkproxy.New(log, etron.IDKParams) - ats, its, err := service.AAZSTokenSource(log, idk, etron.AZSConfig, q) - if err != nil { - return nil, err - } - - // use the etron API for list of vehicles - api := etron.NewAPI(log, ats) - - vehicle, err := ensureVehicleEx( - cc.VIN, func() ([]etron.Vehicle, error) { - ctx, cancel := context.WithTimeout(context.Background(), cc.Timeout) - defer cancel() - return api.Vehicles(ctx) - }, - func(v etron.Vehicle) string { - return v.VIN - }, - ) - - if err == nil { - if v.Title_ == "" { - v.Title_ = vehicle.Nickname - } - - api := id.NewAPI(log, its) - api.Client.Timeout = cc.Timeout - - v.Provider = id.NewProvider(api, vehicle.VIN, cc.Cache) - } - - return v, err -} diff --git a/vehicle/audi.go b/vehicle/audi.go index 9fa4e2e95..25279c17d 100644 --- a/vehicle/audi.go +++ b/vehicle/audi.go @@ -1,28 +1,31 @@ package vehicle import ( + "context" "time" "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" - "github.com/evcc-io/evcc/vehicle/audi" + "github.com/evcc-io/evcc/vehicle/audi/etron" "github.com/evcc-io/evcc/vehicle/vag/idkproxy" "github.com/evcc-io/evcc/vehicle/vag/service" - "github.com/evcc-io/evcc/vehicle/vw" + "github.com/evcc-io/evcc/vehicle/vag/vwidentity" + "github.com/evcc-io/evcc/vehicle/vw/id" ) -// https://github.com/davidgiga1993/AudiAPI // https://github.com/TA2k/ioBroker.vw-connect +// https://github.com/arjenvrh/audi_connect_ha/blob/master/custom_components/audiconnect/audi_services.py // Audi is an api.Vehicle implementation for Audi cars type Audi struct { *embed - *vw.Provider // provides the api implementations + *id.Provider // provides the api implementations } func init() { registry.Add("audi", NewAudiFromConfig) + registry.Add("etron", NewAudiFromConfig) } // NewAudiFromConfig creates a new vehicle @@ -51,21 +54,42 @@ func NewAudiFromConfig(other map[string]interface{}) (api.Vehicle, error) { log := util.NewLogger("audi").Redact(cc.User, cc.Password, cc.VIN) - idk := idkproxy.New(log, audi.IDKParams) - ts, err := service.MbbTokenSource(log, idk, audi.AuthClientID, audi.AuthParams, cc.User, cc.Password) + // get initial VW identity id_token + q, err := vwidentity.Login(log, etron.AuthParams, cc.User, cc.Password) if err != nil { return nil, err } - api := vw.NewAPI(log, ts, audi.Brand, audi.Country) - api.Client.Timeout = cc.Timeout + // exchange initial VW identity id_token for Audi AAZS token + idk := idkproxy.New(log, etron.IDKParams) + ats, its, err := service.AAZSTokenSource(log, idk, etron.AZSConfig, q) + if err != nil { + return nil, err + } - cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles) + // use the etron API for list of vehicles + api := etron.NewAPI(log, ats) + + vehicle, err := ensureVehicleEx( + cc.VIN, func() ([]etron.Vehicle, error) { + ctx, cancel := context.WithTimeout(context.Background(), cc.Timeout) + defer cancel() + return api.Vehicles(ctx) + }, + func(v etron.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) + if v.Title_ == "" { + v.Title_ = vehicle.Nickname } + + api := id.NewAPI(log, its) + api.Client.Timeout = cc.Timeout + + v.Provider = id.NewProvider(api, vehicle.VIN, cc.Cache) } return v, err