From 5c89c03beac5dce10c8c0be6acbdfbc574af3a33 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 21 Feb 2021 16:51:27 +0100 Subject: [PATCH] Add Seat api (#681) --- vehicle/seat.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 vehicle/seat.go diff --git a/vehicle/seat.go b/vehicle/seat.go new file mode 100644 index 000000000..3a9500fc4 --- /dev/null +++ b/vehicle/seat.go @@ -0,0 +1,70 @@ +package vehicle + +import ( + "net/url" + "strings" + "time" + + "github.com/andig/evcc/api" + "github.com/andig/evcc/util" + "github.com/andig/evcc/vehicle/vw" +) + +// https://github.com/trocotronic/weconnect +// https://github.com/TA2k/ioBroker.vw-connect + +// Seat is an api.Vehicle implementation for Seat cars +type Seat struct { + *embed + *vw.Provider // provides the api implementations +} + +func init() { + registry.Add("Seat", NewSeatFromConfig) +} + +// NewSeatFromConfig creates a new vehicle +func NewSeatFromConfig(other map[string]interface{}) (api.Vehicle, error) { + cc := struct { + Title string + Capacity int64 + User, Password, VIN string + Cache time.Duration + }{ + Cache: interval, + } + + if err := util.DecodeOther(other, &cc); err != nil { + return nil, err + } + + v := &Seat{ + embed: &embed{cc.Title, cc.Capacity}, + } + + log := util.NewLogger("seat") + identity := vw.NewIdentity(log, "9dcc70f0-8e79-423a-a3fa-4065d99088b4") + + query := url.Values(map[string][]string{ + "response_type": {"code id_token"}, + "client_id": {"50f215ac-4444-4230-9fb1-fe15cd1a9bcc@apps_vw-dilab_com"}, + "redirect_uri": {"seatconnect://identity-kit/login"}, + "scope": {"openid profile mbb cars birthdate nickname address phone"}, + }) + + err := identity.Login(query, cc.User, cc.Password) + if err == nil { + api := vw.NewAPI(log, identity, "VW", "ES") + + if cc.VIN == "" { + cc.VIN, err = findVehicle(api.Vehicles()) + if err == nil { + log.DEBUG.Printf("found vehicle: %v", cc.VIN) + } + } + + v.Provider = vw.NewProvider(api, strings.ToUpper(cc.VIN), cc.Cache) + } + + return v, err +}