Enyaq: add odometer and vehicle details (#4691)

This commit is contained in:
andig 2022-10-02 16:38:45 +02:00 • committed by GitHub
parent 850ba83721
commit 103107a3f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 25 deletions

View file

@ -53,7 +53,20 @@ func NewEnyaqFromConfig(other map[string]interface{}) (api.Vehicle, error) {
}
api := skoda.NewAPI(log, ts)
cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles)
_, vehicle, err := ensureVehicleWithFeature(
cc.VIN, api.Vehicles,
func(v skoda.Vehicle) (string, skoda.Vehicle) {
return v.VIN, v
},
)
if v.Title_ == "" {
v.Title_ = vehicle.Name
}
if v.Capacity_ == 0 {
v.Capacity_ = int64(vehicle.Specification.Battery.CapacityInKWh)
}
// use Connect credentials to build provider
if err == nil {
@ -65,7 +78,7 @@ func NewEnyaqFromConfig(other map[string]interface{}) (api.Vehicle, error) {
api := skoda.NewAPI(log, ts)
api.Client.Timeout = cc.Timeout
v.Provider = skoda.NewProvider(api, cc.VIN, cc.Cache)
v.Provider = skoda.NewProvider(api, vehicle.VIN, cc.Cache)
}
return v, err

View file

@ -30,21 +30,22 @@ func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API {
return v
}
// Vehicles implements the /vehicles response
func (v *API) Vehicles() ([]string, error) {
// Vehicles implements the /v3/garage response
func (v *API) Vehicles() ([]Vehicle, error) {
var res VehiclesResponse
uri := fmt.Sprintf("%s/v2/garage/vehicles", BaseURI)
uri := fmt.Sprintf("%s/v3/garage", BaseURI)
err := v.GetJSON(uri, &res)
var vehicles []string
if err == nil {
for _, v := range res {
vehicles = append(vehicles, v.VIN)
}
}
return res.Vehicles, err
}
return vehicles, err
// Status implements the /v2/vehicle-status/<vin> response
func (v *API) Status(vin string) (StatusResponse, error) {
var res StatusResponse
uri := fmt.Sprintf("%s/v2/vehicle-status/%s", BaseURI, vin)
err := v.GetJSON(uri, &res)
return res, err
}
// Charger implements the /v1/charging/<vin>/status response

View file

@ -9,5 +9,5 @@ var AuthParams = url.Values{
"response_type": {"code id_token"},
"redirect_uri": {"skodaconnect://oidc.login/"},
"client_id": {"7f045eee-7003-4379-9968-9355ed2adb06@apps_vw-dilab_com"},
"scope": {"openid profile mbb"}, // phone address cars email birthdate badge dealers driversLicense
"scope": {"openid profile mbb mileage"}, // phone address cars email birthdate badge dealers driversLicense
}

View file

@ -9,6 +9,7 @@ import (
// Provider implements the evcc vehicle api
type Provider struct {
statusG func() (StatusResponse, error)
chargerG func() (ChargerResponse, error)
action func(action, value string) error
}
@ -16,6 +17,9 @@ type Provider struct {
// NewProvider provides the evcc vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{
statusG: provider.Cached(func() (StatusResponse, error) {
return api.Status(vin)
}, cache),
chargerG: provider.Cached(func() (ChargerResponse, error) {
return api.Charger(vin)
}, cache),
@ -85,11 +89,15 @@ var _ api.VehicleRange = (*Provider)(nil)
// Range implements the api.VehicleRange interface
func (v *Provider) Range() (rng int64, err error) {
res, err := v.chargerG()
if err == nil {
rng = res.Battery.CruisingRangeElectricInMeters / 1e3
}
return res.Battery.CruisingRangeElectricInMeters / 1e3, err
}
return rng, err
var _ api.VehicleOdometer = (*Provider)(nil)
// Odometer implements the api.VehicleOdometer interface
func (v *Provider) Odometer() (odo float64, err error) {
res, err := v.statusG()
return res.Remote.MileageInKm, err
}
// var _ api.VehicleClimater = (*Provider)(nil)

View file

@ -1,21 +1,48 @@
package skoda
// VehiclesResponse is the /v2/garage/vehicles api
type VehiclesResponse []Vehicle
// VehiclesResponse is the /v3/garage api
type VehiclesResponse struct {
Vehicles []Vehicle
}
type Vehicle struct {
ID, VIN string
Name string // user-given name
LastUpdatedAt string
Specification struct {
Title, Brand, Model string
Battery struct {
CapacityInKWh int
}
}
Specification Specification
// Connectivities
// Capabilities
}
type Specification struct {
Title string
Model string
ModelYear string
Body string
SystemCode string
SystemModelId string
Engine struct {
Typ string `json:"type"`
PowerInKW int
}
Battery struct {
CapacityInKWh int
}
Gearbox struct {
Typ string `json:"type"`
}
TrimLevel string
ManufacturingDate string
MaxChargingPowerInKW int
}
// StatusResponse is the /v2/vehicle-status/<vin> api
type StatusResponse struct {
Remote struct {
MileageInKm float64
}
}
// ChargerResponse is the /v1/charging/<vin>/status api
type ChargerResponse struct {
Plug struct {