PSA: add position api (#2023)
This commit is contained in:
parent
981b23dd56
commit
16bfc70225
2 changed files with 27 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue