Tesla: add position api (#2024)
This commit is contained in:
parent
16bfc70225
commit
553bf56d9f
1 changed files with 19 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ type Tesla struct {
|
|||
vehicle *tesla.Vehicle
|
||||
chargeStateG func() (interface{}, error)
|
||||
vehicleStateG func() (interface{}, error)
|
||||
driveStateG func() (interface{}, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -85,6 +86,7 @@ func NewTeslaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
|
||||
v.chargeStateG = provider.NewCached(v.chargeState, cc.Cache).InterfaceGetter()
|
||||
v.vehicleStateG = provider.NewCached(v.vehicleState, cc.Cache).InterfaceGetter()
|
||||
v.driveStateG = provider.NewCached(v.driveState, cc.Cache).InterfaceGetter()
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
|
@ -99,6 +101,11 @@ func (v *Tesla) vehicleState() (interface{}, error) {
|
|||
return v.vehicle.VehicleState()
|
||||
}
|
||||
|
||||
// driveState implements the climater api
|
||||
func (v *Tesla) driveState() (interface{}, error) {
|
||||
return v.vehicle.DriveState()
|
||||
}
|
||||
|
||||
// SoC implements the api.Vehicle interface
|
||||
func (v *Tesla) SoC() (float64, error) {
|
||||
res, err := v.chargeStateG()
|
||||
|
|
@ -188,6 +195,18 @@ func (v *Tesla) FinishTime() (time.Time, error) {
|
|||
|
||||
// TODO api.Climater implementation has been removed as it drains battery. Re-check at a later time.
|
||||
|
||||
var _ api.VehiclePosition = (*Tesla)(nil)
|
||||
|
||||
// Position implements the api.VehiclePosition interface
|
||||
func (v *Tesla) Position() (float64, float64, error) {
|
||||
res, err := v.driveStateG()
|
||||
if res, ok := res.(*tesla.DriveState); err == nil && ok {
|
||||
return res.Latitude, res.Longitude, nil
|
||||
}
|
||||
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
var _ api.VehicleStartCharge = (*Tesla)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue