Skip to content

Commit

Permalink
Add Seat api (evcc-io#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 21, 2021
1 parent 113150d commit 5c89c03
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions vehicle/seat.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 5c89c03

Please sign in to comment.