Skip to content

Better event handling#256

Draft
rwb27 wants to merge 1 commit into
mainfrom
publish-event
Draft

Better event handling#256
rwb27 wants to merge 1 commit into
mainfrom
publish-event

Conversation

@rwb27
Copy link
Copy Markdown
Collaborator

@rwb27 rwb27 commented Feb 2, 2026

This PR has rather run away with me. It will need splitting and tidying before merging.

It started out attempting to centralise event handling into a MessageBroker class, which would then mean events don't cause errors if they fire before the event loop starts. This basically worked.

It also updated notification-related stuff to use the syntax thing.properties[name].observe(stream) rather than thing.observe_property(name, stream) which deduplicated the logic that found the descriptor.

Lastly, and most problematically, it attempts to implement the webthingsubprotocol sub-protocol for websocket messages. This requires a bunch of changes - in particular, the WoT standard has fewer statuses for actions ("cancelled" is gone).

I should break it down so that we implement the first one, then the second one, then the third one - ideally in 3 separate PRs.

@rwb27 rwb27 added this to the v0.3.0 milestone May 7, 2026
This refactors handling of property and action observations. In particular, it:

* Introduces a MessageBroker class to handle pub/sub messaging centrally. This eliminates duplicated code from descriptors and should be much clearer.
* Adds a `publish` method to the thing server interface for easy publication of events.
* No longer errors if events are published before the event loop is active: they are silently ignored.
* Removes the option to set properties without emitting an event: this is no longer needed - it was only ever done to suppress errors.
* Separates handling of pub/sub messages from websocket protocol considerations.

This does not change the websocket protocol.

I've updated tests, but have not yet added tests for `MessageBroker`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant