Combine --watch functionality with --server#110
Open
victor-hucklenbroich wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RESOLVES #94
Add a persistent BLE notification subscription to the HTTP server, gated
on a new
watch: boolconfig option. When enabled, the server mirrorsdesk state changes to stdout (matching the CLI
--watchbehaviour) andexposes a new
/eventswebsocket endpoint that streams JSON updates ofthe form {"height": , "speed": <mm/s>} to connected clients.
To support multiple consumers of the same notification stream, the Desk
class gains an in-process pub/sub layer (subscribe / unsubscribe ->
start_watching / stop_watching) with a cached latest_height and
latest_speed. The existing
watch_height_speedCLI entrypoint isreimplemented on top of this layer with no change in behaviour.
The TCP server is unchanged and remains request/response only.
Adds corresponding new flag (
watch: True / False) to config.yaml. Defaults tofalse, so existing configs are unaffected until they opt in.Re-establish watch subscription after reconnect
While working on the server watch changes I found a pre-existing gap in the reconnect handling. disconnect_callback transparently reconnects the BLE client, but the notification subscription dies with the old connection while desk._watching stays True. After a reconnect the subscription is never rebuilt and the if self._watching: return guard in start_watching would prevent it anyway so the height/speed event stream goes silently dead.
This affects both the new --server --watch path and the existing CLI --watch. It isn't introduced by the server watch changes, but a long-running server will eventually hit it, so it's worth fixing here.
The fix is small: Desk.mark_disconnected() clears the watching flag on disconnect and reports whether watching was active, and connect re-calls start_watching on the new connection when it was. Existing subscribers are preserved, so clients keep receiving events seamlessly across a reconnect.
Functionality (new and existing) is manually tested on my local macOS machine with my Ikea Idasen