From 981b23dd56bf344b746eaae32366d7ce890d0918 Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 11 Dec 2021 12:47:08 +0100 Subject: [PATCH] Add vehicle position api (#2021) --- api/api.go | 5 +++++ cmd/dumper.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/api/api.go b/api/api.go index 6707ed9fa..985328762 100644 --- a/api/api.go +++ b/api/api.go @@ -164,6 +164,11 @@ type VehicleOdometer interface { Odometer() (float64, error) } +// VehiclePosition returns the vehicles position in latitude and longitude +type VehiclePosition interface { + Position() (float64, float64, error) +} + // VehicleStartCharge starts the charging session on the vehicle side type VehicleStartCharge interface { StartCharge() error diff --git a/cmd/dumper.go b/cmd/dumper.go index 69247bb8b..1a38eba91 100644 --- a/cmd/dumper.go +++ b/cmd/dumper.go @@ -162,6 +162,14 @@ func (d *dumper) Dump(name string, v interface{}) { } } + if v, ok := v.(api.VehiclePosition); ok { + if lat, lon, err := v.Position(); err != nil { + fmt.Fprintf(w, "Position:\t%v\n", err) + } else { + fmt.Fprintf(w, "Position:\t%v,%v\n", lat, lon) + } + } + if v, ok := v.(api.Vehicle); ok { fmt.Fprintf(w, "Capacity:\t%dkWh\n", v.Capacity()) if len(v.Identifiers()) > 0 {