Cupra: fix api (#15081)
This commit is contained in:
parent
aa2964d36b
commit
530d7a1bdb
3 changed files with 50 additions and 12 deletions
|
|
@ -52,7 +52,23 @@ func (v *API) Vehicles(userID string) ([]Vehicle, error) {
|
|||
// Status implements the /status response
|
||||
func (v *API) Status(userID, vin string) (Status, error) {
|
||||
var res Status
|
||||
uri := fmt.Sprintf("%s/v2/users/%s/vehicles/%s/mycar", BaseURL, userID, vin)
|
||||
uri := fmt.Sprintf("%s/v5/users/%s/vehicles/%s/mycar", BaseURL, userID, vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ParkingPosition implements the /parkingposition response
|
||||
func (v *API) ParkingPosition(vin string) (Position, error) {
|
||||
var res Position
|
||||
uri := fmt.Sprintf("%s/v1/vehicles/%s/parkingposition", BaseURL, vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Mileage implements the /mileage response
|
||||
func (v *API) Mileage(vin string) (Mileage, error) {
|
||||
var res Mileage
|
||||
uri := fmt.Sprintf("%s/v1/vehicles/%s/mileage", BaseURL, vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
return res, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@ import (
|
|||
|
||||
// Provider is an api.Vehicle implementation for Seat Cupra cars
|
||||
type Provider struct {
|
||||
statusG func() (Status, error)
|
||||
action func(string, string) error
|
||||
statusG func() (Status, error)
|
||||
positionG func() (Position, error)
|
||||
milageG func() (Mileage, error)
|
||||
action func(string, string) error
|
||||
}
|
||||
|
||||
// NewProvider creates a vehicle api provider
|
||||
|
|
@ -20,6 +22,12 @@ func NewProvider(api *API, userID, vin string, cache time.Duration) *Provider {
|
|||
statusG: provider.Cached(func() (Status, error) {
|
||||
return api.Status(userID, vin)
|
||||
}, cache),
|
||||
positionG: provider.Cached(func() (Position, error) {
|
||||
return api.ParkingPosition(vin)
|
||||
}, cache),
|
||||
milageG: provider.Cached(func() (Mileage, error) {
|
||||
return api.Mileage(vin)
|
||||
}, cache),
|
||||
action: func(action, cmd string) error {
|
||||
return api.Action(vin, action, cmd)
|
||||
},
|
||||
|
|
@ -32,7 +40,7 @@ var _ api.Battery = (*Provider)(nil)
|
|||
// Soc implements the api.Vehicle interface
|
||||
func (v *Provider) Soc() (float64, error) {
|
||||
res, err := v.statusG()
|
||||
return res.Engines.Primary.Level, err
|
||||
return res.Engines.Primary.LevelPct, err
|
||||
}
|
||||
|
||||
var _ api.ChargeState = (*Provider)(nil)
|
||||
|
|
@ -81,15 +89,23 @@ var _ api.VehicleRange = (*Provider)(nil)
|
|||
// Range implements the api.VehicleRange interface
|
||||
func (v *Provider) Range() (int64, error) {
|
||||
res, err := v.statusG()
|
||||
return int64(res.Engines.Primary.Range.Value), err
|
||||
return int64(res.Engines.Primary.RangeKm), err
|
||||
}
|
||||
|
||||
var _ api.VehicleOdometer = (*Provider)(nil)
|
||||
|
||||
// Odometer implements the api.VehicleOdometer interface
|
||||
func (v *Provider) Odometer() (float64, error) {
|
||||
res, err := v.statusG()
|
||||
return res.Measurements.MileageKm, err
|
||||
res, err := v.milageG()
|
||||
return res.MileageKm, err
|
||||
}
|
||||
|
||||
var _ api.VehiclePosition = (*Provider)(nil)
|
||||
|
||||
// Position implements the api.VehiclePosition interface
|
||||
func (v *Provider) Position() (float64, float64, error) {
|
||||
res, err := v.positionG()
|
||||
return res.Lat, res.Lon, err
|
||||
}
|
||||
|
||||
var _ api.VehicleClimater = (*Provider)(nil)
|
||||
|
|
|
|||
|
|
@ -10,11 +10,8 @@ type Vehicle struct {
|
|||
type Engine struct {
|
||||
Type string
|
||||
FuelType string
|
||||
Range struct {
|
||||
Value float64
|
||||
Unit string
|
||||
}
|
||||
Level float64
|
||||
RangeKm float64
|
||||
LevelPct float64
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
|
|
@ -28,6 +25,7 @@ type Status struct {
|
|||
ChargeMode string
|
||||
Active bool
|
||||
RemainingTime int64
|
||||
CurrentPct float64
|
||||
ProgressBarPct float64
|
||||
}
|
||||
Climatisation struct {
|
||||
|
|
@ -41,3 +39,11 @@ type Status struct {
|
|||
MileageKm float64
|
||||
}
|
||||
}
|
||||
|
||||
type Mileage struct {
|
||||
MileageKm float64
|
||||
}
|
||||
|
||||
type Position struct {
|
||||
Lat, Lon float64
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue