diff --git a/internal/devices/powergenius/powergenius.go b/internal/devices/powergenius/powergenius.go index ecb5239..280ea82 100644 --- a/internal/devices/powergenius/powergenius.go +++ b/internal/devices/powergenius/powergenius.go @@ -24,6 +24,9 @@ type Client struct { stopChan chan struct{} running bool + // Connection health tracking + lastAliveTime time.Time + // Auto fan management autoFanEnabled bool lastFanMode string // Remember last manual mode @@ -104,6 +107,9 @@ func (c *Client) Start() error { return nil } + // Initialize connection tracking + c.lastAliveTime = time.Now() + // Try to connect, but don't fail if it doesn't work // The poll loop will keep trying _ = c.Connect() @@ -165,9 +171,17 @@ func (c *Client) pollLoop() { status.Connected = true // Check if device is actually alive (not just TCP connected) - // If voltage is 0 and temperature is 0, device is probably off + // If voltage is 0 and temperature is 0, device might be temporarily idle + // Use a 3-second timeout before marking as disconnected (helps with morse code pauses) if status.Voltage == 0 && status.Temperature == 0 { - status.Connected = false + // Check if we've seen valid data recently (within 3 seconds) + if time.Since(c.lastAliveTime) > 3*time.Second { + status.Connected = false + } + // else: Keep Connected = true (device is probably just idle between morse letters) + } else { + // Valid data received, update lastAliveTime + c.lastAliveTime = time.Now() } // Peak hold logic - keep highest power for 1 second