Loadpoint: add asleep messaging event if wakeup fails (#23116)

This commit is contained in:
andig 2025-08-24 16:50:41 +02:00 • committed by GitHub
parent 4b0524e392
commit 0f70bb3106
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 63 additions and 27 deletions

View file

@ -7,9 +7,18 @@ import (
"github.com/benbjohnson/clock"
)
const wakeupTimeout = 30 * time.Second
const (
wakeupTimeout = 30 * time.Second
wakeupAttempts = 6
)
const wakeupAttempts = 6 // wakeupAttempts is the count of wakeup attempts
type WakeUpEvent int
const (
WakeUpTimerInactive WakeUpEvent = iota
WakeUpTimerElapsed
WakeUpTimerFinished
)
// Timer measures active time between start and stop events
type Timer struct {
@ -48,20 +57,22 @@ func (m *Timer) Stop() {
m.started = time.Time{}
}
// Expired checks if the timer has elapsed and if resets its status
func (m *Timer) Expired() bool {
// Elapsed checks if the timer has elapsed and if resets its status
func (m *Timer) Elapsed() WakeUpEvent {
m.Lock()
defer m.Unlock()
res := !m.started.IsZero() && (m.clck.Since(m.started) >= wakeupTimeout)
if res {
m.wakeupAttemptsLeft--
if m.wakeupAttemptsLeft == 0 {
m.started = time.Time{}
} else {
m.started = m.clck.Now()
}
if m.started.IsZero() || m.clck.Since(m.started) < wakeupTimeout {
return WakeUpTimerInactive
}
return res
if m.wakeupAttemptsLeft == 0 {
m.started = time.Time{}
return WakeUpTimerFinished
}
m.wakeupAttemptsLeft--
m.started = m.clck.Now()
return WakeUpTimerElapsed
}