forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |