Replaced direct notification timer cache access with a public method.
This commit is contained in:
@@ -179,6 +179,14 @@ class NotificationService:
|
|||||||
|
|
||||||
return body_text
|
return body_text
|
||||||
|
|
||||||
|
def get_last_notification_time(self, domain: str) -> float:
|
||||||
|
"""Get the timestamp of the last notification sent for a domain.
|
||||||
|
|
||||||
|
:param domain: The stream domain.
|
||||||
|
:return: Unix timestamp of last notification, or 0 if never notified.
|
||||||
|
"""
|
||||||
|
return self.notification_timers_cache.get(domain, 0)
|
||||||
|
|
||||||
def _can_notify(self, domain: str) -> bool:
|
def _can_notify(self, domain: str) -> bool:
|
||||||
"""Check if enough time has passed to send another notification.
|
"""Check if enough time has passed to send another notification.
|
||||||
|
|
||||||
|
|||||||
@@ -163,8 +163,6 @@ class StreamMonitor:
|
|||||||
# Initialize timer cache entries to prevent KeyError on first access
|
# Initialize timer cache entries to prevent KeyError on first access
|
||||||
if domain not in self.offline_timer_cache:
|
if domain not in self.offline_timer_cache:
|
||||||
self.offline_timer_cache[domain] = 0
|
self.offline_timer_cache[domain] = 0
|
||||||
if domain not in self.notification_service.notification_timers_cache:
|
|
||||||
self.notification_service.notification_timers_cache[domain] = 0
|
|
||||||
|
|
||||||
# Does the last known stream state lack connect/disconnect?
|
# Does the last known stream state lack connect/disconnect?
|
||||||
if (
|
if (
|
||||||
@@ -257,7 +255,7 @@ class StreamMonitor:
|
|||||||
# instead of a title change to avoid confusion.
|
# instead of a title change to avoid confusion.
|
||||||
if (
|
if (
|
||||||
self.offline_timer_cache[domain]
|
self.offline_timer_cache[domain]
|
||||||
> self.notification_service.notification_timers_cache[domain]
|
> self.notification_service.get_last_notification_time(domain)
|
||||||
):
|
):
|
||||||
await self.notification_service.notify_stream_live(
|
await self.notification_service.notify_stream_live(
|
||||||
domain,
|
domain,
|
||||||
|
|||||||
Reference in New Issue
Block a user