From cf5b7af068e2714af48e580edd95c5dec4086a17 Mon Sep 17 00:00:00 2001 From: Shynd Date: Sat, 5 Nov 2022 15:49:39 -0400 Subject: [PATCH 1/2] only notify once a minute --- octoprint_webhooks/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/octoprint_webhooks/__init__.py b/octoprint_webhooks/__init__.py index c283135..2e34288 100644 --- a/octoprint_webhooks/__init__.py +++ b/octoprint_webhooks/__init__.py @@ -6,6 +6,9 @@ import time import sys +from datetime import datetime +from datetime import timedelta + from io import BytesIO from PIL import Image @@ -135,6 +138,7 @@ class WebhooksPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplatePl octoprint.plugin.EventHandlerPlugin, octoprint.plugin.AssetPlugin, octoprint.plugin.SimpleApiPlugin, octoprint.plugin.ProgressPlugin): def __init__(self): + self.last_user_action_notification = datetime.now() - timedelta(seconds=60) self.triggered = False self.last_print_progress = -1 self.last_print_progress_milestones = [] @@ -569,8 +573,12 @@ def recv_callback(self, comm_instance, line, *args, **kwargs): # Found keyword, fire event and block until other text is received if "echo:busy: paused for user" in line: if not self.triggered: - eventManager().fire(Events.PLUGIN_WEBHOOKS_NOTIFY) self.triggered = True + + if timedelta.total_seconds(datetime.now() - self.last_user_action_notification) > 60: + eventManager().fire(Events.PLUGIN_WEBHOOKS_NOTIFY) + self.last_user_action_notification = datetime.now() + # Other text, we may fire another event if we encounter "paused for user" again else: self.triggered = False From a14e9c6220a7e537cb6a99dd4410dab296379f19 Mon Sep 17 00:00:00 2001 From: Shynd Date: Sat, 5 Nov 2022 16:02:30 -0400 Subject: [PATCH 2/2] combine import --- octoprint_webhooks/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/octoprint_webhooks/__init__.py b/octoprint_webhooks/__init__.py index 2e34288..6ecc20e 100644 --- a/octoprint_webhooks/__init__.py +++ b/octoprint_webhooks/__init__.py @@ -6,8 +6,7 @@ import time import sys -from datetime import datetime -from datetime import timedelta +from datetime import datetime, timedelta from io import BytesIO from PIL import Image @@ -578,7 +577,7 @@ def recv_callback(self, comm_instance, line, *args, **kwargs): if timedelta.total_seconds(datetime.now() - self.last_user_action_notification) > 60: eventManager().fire(Events.PLUGIN_WEBHOOKS_NOTIFY) self.last_user_action_notification = datetime.now() - + # Other text, we may fire another event if we encounter "paused for user" again else: self.triggered = False