Wait for vehicle wakeup (#1262)

This commit is contained in:
andig 2021-08-02 10:19:07 +02:00 • committed by GitHub
parent 2b430ae9b0
commit e8e5584003
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View file

@ -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
}

View file

@ -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)
}
}