From 36d5ab57563e9ef874b484c2bd97b1288d26d7b6 Mon Sep 17 00:00:00 2001 From: premultiply <4681172+premultiply@users.noreply.github.com> Date: Mon, 6 Oct 2025 16:28:57 +0200 Subject: [PATCH] add timeout to charger, vehicle, dump --- cmd/charger.go | 4 +++- cmd/dump.go | 5 ++++- cmd/vehicle.go | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/charger.go b/cmd/charger.go index 12afb670d6..d70b78c5d2 100644 --- a/cmd/charger.go +++ b/cmd/charger.go @@ -29,6 +29,7 @@ func init() { chargerCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription) chargerCmd.Flags().IntP(flagPhases, "p", 0, flagPhasesDescription) chargerCmd.Flags().Bool(flagHeartbeat, false, flagHeartbeatDescription) + chargerCmd.Flags().Duration(flagTimeout, time.Second, flagTimeoutDescription) } func runCharger(cmd *cobra.Command, args []string) { @@ -125,7 +126,8 @@ func runCharger(cmd *cobra.Command, args []string) { } if !flagUsed { - d := dumper{len: len(chargers)} + timeout, _ := cmd.Flags().GetDuration(flagTimeout) + d := dumper{len: len(chargers), timeout: timeout} flag := cmd.Flag(flagDiagnose).Changed for _, dev := range chargers { diff --git a/cmd/dump.go b/cmd/dump.go index a99337e52e..9685bd8f0c 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "text/template" + "time" "github.com/Masterminds/sprig/v3" "github.com/evcc-io/evcc/core" @@ -33,6 +34,7 @@ func init() { rootCmd.AddCommand(dumpCmd) dumpConfig = dumpCmd.Flags().Bool("cfg", false, "Dump config file") + dumpCmd.Flags().Duration(flagTimeout, time.Second, flagTimeoutDescription) } func handle[T any](name string, h config.Handler[T]) config.Device[T] { @@ -90,7 +92,8 @@ func runDump(cmd *cobra.Command, args []string) { log.FATAL.Fatal(err) } - d := dumper{len: 2} + timeout, _ := cmd.Flags().GetDuration(flagTimeout) + d := dumper{len: 2, timeout: timeout} d.Header("config", "=") fmt.Println("") diff --git a/cmd/vehicle.go b/cmd/vehicle.go index d4c6502f57..709bcf4e24 100644 --- a/cmd/vehicle.go +++ b/cmd/vehicle.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "strconv" + "time" "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util/config" @@ -25,6 +26,7 @@ func init() { vehicleCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription) vehicleCmd.Flags().Bool(flagDiagnose, false, flagDiagnoseDescription) vehicleCmd.Flags().Bool(flagCloud, false, flagCloudDescription) + vehicleCmd.Flags().Duration(flagTimeout, time.Second, flagTimeoutDescription) } func runVehicle(cmd *cobra.Command, args []string) { @@ -112,7 +114,8 @@ func runVehicle(cmd *cobra.Command, args []string) { } if !flagUsed { - d := dumper{len: len(vehicles)} + timeout, _ := cmd.Flags().GetDuration(flagTimeout) + d := dumper{len: len(vehicles), timeout: timeout} flag := cmd.Flag(flagDiagnose).Changed for _, dev := range vehicles {