From e8e5584003c17f2b57871c6a29d8647b0eb30db7 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 2 Aug 2021 10:19:07 +0200 Subject: [PATCH] Wait for vehicle wakeup (#1262) --- cmd/soc/main.go | 2 +- cmd/vehicle.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cmd/soc/main.go b/cmd/soc/main.go index b3debfec1..8c24b88c2 100644 --- a/cmd/soc/main.go +++ b/cmd/soc/main.go @@ -80,7 +80,7 @@ func main() { soc, err := v.SoC() if err != nil { - if errors.As(err, &api.ErrMustRetry) { + if errors.Is(err, api.ErrMustRetry) { time.Sleep(5 * time.Second) continue } diff --git a/cmd/vehicle.go b/cmd/vehicle.go index 917e85a59..179c2caaf 100644 --- a/cmd/vehicle.go +++ b/cmd/vehicle.go @@ -1,6 +1,10 @@ package cmd import ( + "errors" + "fmt" + "time" + "github.com/andig/evcc/api" "github.com/andig/evcc/server" "github.com/andig/evcc/util" @@ -45,7 +49,32 @@ func runVehicle(cmd *cobra.Command, args []string) { } d := dumper{len: len(vehicles)} +NEXT: for name, v := range vehicles { + start := time.Now() + + WAIT: + // wait up to 1m for the vehicle to wakeup + for { + if time.Since(start) > time.Minute { + log.ERROR.Println(api.ErrTimeout) + continue NEXT + } + + if _, err := v.SoC(); err != nil { + if errors.Is(err, api.ErrMustRetry) { + time.Sleep(5 * time.Second) + fmt.Print(".") + continue WAIT + } + + log.ERROR.Println(err) + continue NEXT + } + + break + } + d.DumpWithHeader(name, v) } }