jellyfin-qbittorrent-monitor: fix hysterisis
This commit is contained in:
@@ -61,6 +61,7 @@ class JellyfinQBittorrentMonitor:
|
||||
self.streaming_start_delay = streaming_start_delay
|
||||
self.streaming_stop_delay = streaming_stop_delay
|
||||
self.last_state_change = 0
|
||||
self._last_seen_state = None # tracks previous poll's streaming_active for flicker detection
|
||||
|
||||
# Webhook receiver: allows Jellyfin to push events instead of waiting for the poll
|
||||
self.webhook_port = webhook_port
|
||||
@@ -355,12 +356,24 @@ class JellyfinQBittorrentMonitor:
|
||||
pass
|
||||
|
||||
def should_change_state(self, new_streaming_state: bool) -> bool:
|
||||
"""Apply hysteresis to prevent rapid state changes"""
|
||||
"""Apply hysteresis to prevent rapid state changes.
|
||||
|
||||
The delay must be contiguous: if the session flickers (absent→present
|
||||
while a stop-countdown is in progress, or vice versa), the timer resets
|
||||
so brief gaps don't accumulate into a spurious state transition.
|
||||
Routine repeated presence (e.g. webhook PlaybackProgress every second)
|
||||
does NOT reset the timer — only a direction reversal does.
|
||||
"""
|
||||
now = time.time()
|
||||
|
||||
if new_streaming_state == self.last_streaming_state:
|
||||
if self._last_seen_state != self.last_streaming_state:
|
||||
self.last_state_change = now
|
||||
self._last_seen_state = new_streaming_state
|
||||
return False
|
||||
|
||||
self._last_seen_state = new_streaming_state
|
||||
|
||||
time_since_change = now - self.last_state_change
|
||||
|
||||
if new_streaming_state and not self.last_streaming_state:
|
||||
|
||||
Reference in New Issue
Block a user