Mini: upgrade api
This commit is contained in:
parent
d1f78bafeb
commit
6849ca3083
2 changed files with 18 additions and 7 deletions
|
|
@ -17,11 +17,21 @@ type BMW struct {
|
|||
|
||||
func init() {
|
||||
registry.Add("bmw", NewBMWFromConfig)
|
||||
registry.Add("mini", NewBMWFromConfig)
|
||||
registry.Add("mini", NewMiniFromConfig)
|
||||
}
|
||||
|
||||
// NewBMWFromConfig creates a new vehicle
|
||||
func NewBMWFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
||||
return NewBMWMiniFromConfig("bmw", other)
|
||||
}
|
||||
|
||||
// NewMiniFromConfig creates a new vehicle
|
||||
func NewMiniFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
||||
return NewBMWMiniFromConfig("mini", other)
|
||||
}
|
||||
|
||||
// NewBMWMiniFromConfig creates a new vehicle
|
||||
func NewBMWMiniFromConfig(brand string, other map[string]interface{}) (api.Vehicle, error) {
|
||||
cc := struct {
|
||||
embed `mapstructure:",squash"`
|
||||
User, Password, VIN string
|
||||
|
|
@ -38,14 +48,14 @@ func NewBMWFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
embed: &cc.embed,
|
||||
}
|
||||
|
||||
log := util.NewLogger("bmw").Redact(cc.User, cc.Password, cc.VIN)
|
||||
log := util.NewLogger(brand).Redact(cc.User, cc.Password, cc.VIN)
|
||||
identity := bmw.NewIdentity(log)
|
||||
|
||||
if err := identity.Login(cc.User, cc.Password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
api := bmw.NewAPI(log, identity)
|
||||
api := bmw.NewAPI(log, brand, identity)
|
||||
|
||||
var err error
|
||||
if cc.VIN == "" {
|
||||
|
|
|
|||
|
|
@ -16,18 +16,19 @@ import (
|
|||
const (
|
||||
ApiURI = "https://b2vapi.bmwgroup.com/webapi/v1"
|
||||
CocoApiURI = "https://cocoapi.bmwgroup.com"
|
||||
XUserAgent = "android(v1.07_20200330);bmw;1.7.0(11152)"
|
||||
)
|
||||
|
||||
// API is an api.Vehicle implementation for BMW cars
|
||||
type API struct {
|
||||
*request.Helper
|
||||
xUserAgent string
|
||||
}
|
||||
|
||||
// NewAPI creates a new vehicle
|
||||
func NewAPI(log *util.Logger, identity oauth2.TokenSource) *API {
|
||||
func NewAPI(log *util.Logger, brand string, identity oauth2.TokenSource) *API {
|
||||
v := &API{
|
||||
Helper: request.NewHelper(log),
|
||||
Helper: request.NewHelper(log),
|
||||
xUserAgent: fmt.Sprintf("android(v1.07_20200330);%s;1.7.0(11152)", brand),
|
||||
}
|
||||
|
||||
// replace client transport with authenticated transport
|
||||
|
|
@ -64,7 +65,7 @@ func (v *API) Status(vin string) (VehicleStatus, error) {
|
|||
uri := fmt.Sprintf("%s/eadrax-vcs/v1/vehicles?apptimezone=60&appDateTime=%d&vin=%s", CocoApiURI, time.Now().Unix(), vin)
|
||||
|
||||
req, err := request.New(http.MethodGet, uri, nil, map[string]string{
|
||||
"X-User-Agent": XUserAgent,
|
||||
"X-User-Agent": v.xUserAgent,
|
||||
})
|
||||
if err == nil {
|
||||
err = v.DoJSON(req, &resp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue