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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2025-02-07 06:08:49 -05:00
parent 71ab2fb80e
commit b8388db18d
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B

View File

@ -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(