From b8388db18de8c746423e1dd251a60a802bcc41fa Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 7 Feb 2025 06:08:49 -0500 Subject: [PATCH] klippy_connection: improve subscription request handling If the connection requesting the subscription already had an outstanding subscription, remove it before processing. This prevents immediate status updates from being pushed to the requesting connection. Don't add connections to the dictionary of subscribed connections if the request is an empty object, as this is a request to unsubscribe from all objects. Signed-off-by: Eric Callahan --- moonraker/components/klippy_connection.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/moonraker/components/klippy_connection.py b/moonraker/components/klippy_connection.py index 40030eb..565cd60 100644 --- a/moonraker/components/klippy_connection.py +++ b/moonraker/components/klippy_connection.py @@ -624,6 +624,8 @@ class KlippyConnection: raise self.server.error( "No connection associated with subscription request" ) + # if the connection has an existing subscription pop it off + self.subscriptions.pop(conn, None) requested_sub: Subscription = args.get('objects', {}) all_subs: Subscription = dict(requested_sub) # Build the subscription request from a superset of all client subscriptions @@ -695,7 +697,8 @@ class KlippyConnection: if obj_name not in all_status: del self.subscription_cache[obj_name] result['status'] = pruned_status - self.subscriptions[conn] = requested_sub + if requested_sub: + self.subscriptions[conn] = requested_sub return result async def _request_standard(