PSA: add position api (#2023)

This commit is contained in:
andig 2021-12-11 12:51:46 +01:00 • committed by GitHub
parent 981b23dd56
commit 16bfc70225
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -138,3 +138,18 @@ func (v *Provider) Climater() (active bool, outsideTemp float64, targetTemp floa
return active, outsideTemp, targetTemp, err
}
var _ api.VehiclePosition = (*Provider)(nil)
// Position implements the api.VehiclePosition interface
func (v *Provider) Position() (float64, float64, error) {
res, err := v.statusG()
if res, ok := res.(Status); err == nil && ok {
if coord := res.LastPosition.Geometry.Coordinates; len(coord) == 2 {
return coord[0], coord[1], nil
}
return 0, 0, api.ErrNotAvailable
}
return 0, 0, err
}

View file

@ -37,6 +37,18 @@ type Status struct {
Odometer struct {
Mileage float64
} `json:"timed.odometer"`
LastPosition struct {
Type string
Geometry struct {
Type string
Coordinates []float64
}
Properties struct {
UpdatedAt time.Time
Type string
Heading int
}
}
}
// Energy is the /status partial energy response