diff --git a/core/loadpoint_vehicle.go b/core/loadpoint_vehicle.go index 9c61b5b3f..c8e8afa99 100644 --- a/core/loadpoint_vehicle.go +++ b/core/loadpoint_vehicle.go @@ -165,19 +165,21 @@ func (lp *Loadpoint) setActiveVehicle(v api.Vehicle) { } func (lp *Loadpoint) wakeUpVehicle() { - // charger - if c, ok := lp.charger.(api.Resurrector); ok { - lp.log.DEBUG.Println("wake-up charger") - if err := c.WakeUp(); err != nil { - lp.log.ERROR.Printf("wake-up charger: %v", err) + if lp.wakeUpTimer.wakeupAttemptsLeft%2 != 0 { + // charger + if c, ok := lp.charger.(api.Resurrector); ok { + lp.log.DEBUG.Printf("wake-up charger, attempts left: %d", lp.wakeUpTimer.wakeupAttemptsLeft) + if err := c.WakeUp(); err != nil { + lp.log.ERROR.Printf("wake-up charger: %v", err) + } } - } - - // vehicle - if vs, ok := lp.GetVehicle().(api.Resurrector); ok { - lp.log.DEBUG.Println("wake-up vehicle") - if err := vs.WakeUp(); err != nil { - lp.log.ERROR.Printf("wake-up vehicle: %v", err) + } else { + // vehicle + if vs, ok := lp.GetVehicle().(api.Resurrector); ok { + lp.log.DEBUG.Printf("wake-up vehicle, attempts left: %d", lp.wakeUpTimer.wakeupAttemptsLeft) + if err := vs.WakeUp(); err != nil { + lp.log.ERROR.Printf("wake-up vehicle: %v", err) + } } } } diff --git a/core/timer.go b/core/timer.go index d34889e85..59befe191 100644 --- a/core/timer.go +++ b/core/timer.go @@ -9,11 +9,14 @@ import ( const wakeupTimeout = 30 * time.Second +const wakeupAttempts = 6 // wakeupAttempts is the count of wakeup attempts + // Timer measures active time between start and stop events type Timer struct { sync.Mutex - clck clock.Clock - started time.Time + clck clock.Clock + started time.Time + wakeupAttemptsLeft int } // NewTimer creates timer that can expire @@ -28,6 +31,8 @@ func (m *Timer) Start() { m.Lock() defer m.Unlock() + m.wakeupAttemptsLeft = wakeupAttempts + if !m.started.IsZero() { return } @@ -50,7 +55,12 @@ func (m *Timer) Expired() bool { res := !m.started.IsZero() && (m.clck.Since(m.started) >= wakeupTimeout) if res { - m.started = time.Time{} + m.wakeupAttemptsLeft-- + if m.wakeupAttemptsLeft == 0 { + m.started = time.Time{} + } else { + m.started = m.clck.Now() + } } return res