Retry vehicle wake-up if necessary (#11707)
This commit is contained in:
parent
d59986cbc3
commit
2f30247115
2 changed files with 27 additions and 15 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue