Skip to content

Subscriber abstracted class - #64

Merged
mrstegeman merged 8 commits into
WebThingsIO:masterfrom
pimoens:improved-subscriptions
Jan 10, 2020
Merged

Subscriber abstracted class#64
mrstegeman merged 8 commits into
WebThingsIO:masterfrom
pimoens:improved-subscriptions

Conversation

@pimoens

@pimoens pimoens commented Jan 9, 2020

Copy link
Copy Markdown
Contributor

When I wanted to use the webthing-python package without Tornado I ran into several issues, because the subscribers on a Thing are Tornado WebSockets resulting in a dependency between a Thing and tornado.websockets.

To resolve this I created an abstract method named Subscriber. It utilizes the Observer Pattern and describes update methods which are called by a Thing when notifying the subscribers. These update methods can be implemented using tornado.websockets or any alternative. I extended the ThingHandler and implemented the Subscriber class.

Result
The webthing-python package can now be used regardless the choice of Python web server.

Comment thread webthing/server.py Outdated
"""Allow connections from all origins."""
return True

def update(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like update() is used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can indeed be removed. I originally started using one update method, but then realized a Thing has separate notifications for an Action, Event and Property.

Comment thread webthing/server.py Outdated

def update_property(self, property_):
"""
Receive update from a Thing about an Property.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick about the comments on these three methods... They should probably say Send an update about X, rather than Receive, given that this is at the server layer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used "Receive" since the Subscriber receives an update while a Thing (the subject) sends the notification according to the Observer pattern. Then again a Thing uses the method to send an update to the Subscriber, so I'll change that.

@mrstegeman

Copy link
Copy Markdown
Contributor

I assume you've rebuilt the whole server layer to use a different framework. Do you mind if I ask which framework, and why?

@pimoens

pimoens commented Jan 10, 2020

Copy link
Copy Markdown
Contributor Author

I assume you've rebuilt the whole server layer to use a different framework. Do you mind if I ask which framework, and why?

I have created a gateway which brings together sensors from different sources (Kafka, external APIs..). This gateway has been implemented using Flask, because of the large, active community and the high amount of extensions. Of course I then wanted to use this package to make the gateway Web Thing Model compliant.

@mrstegeman

Copy link
Copy Markdown
Contributor

Neat!

@mrstegeman
mrstegeman merged commit 96a9def into WebThingsIO:master Jan 10, 2020
@pimoens
pimoens deleted the improved-subscriptions branch January 10, 2020 18:22
@pimoens

pimoens commented Jan 13, 2020

Copy link
Copy Markdown
Contributor Author

Is there a chance you might launch a new release for these changes? It would be nice to be able to use the package.

@mrstegeman

Copy link
Copy Markdown
Contributor

Done! 0.12.1 is out now.

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.

2 participants