Skip to content

Add feed callback mechanism #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 28, 2020
Merged

Conversation

brentru
Copy link
Member

@brentru brentru commented Sep 28, 2020

Addresses #45

Tested on Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit PyPortal with samd51j20

Test is the example modified to include remove_callback
Expected behavior - should not fire a second time since it's removed

def on_battery_msg(client, topic, message):
    # Method called whenever user/feeds/battery has a new value
    print("Battery level: {}v".format(message))

    print("Removing feed callback...")
    io.remove_feed_callback("battery")

Behavior:

code.py output:
Connecting to WiFi...
Connected!
Connecting to Adafruit IO...
Connected to Adafruit IO!  Listening for DemoFeed changes...
Subscribed to brubell/feeds/battery with QOS level 0
Battery level: 0.15v
Removing feed callback...
Feed battery received new value: 0.42 <= OK, executed on_message instead of on_battery_msg

@brentru brentru requested a review from a team September 28, 2020 15:38
@brentru brentru merged commit e458105 into adafruit:master Sep 28, 2020

"""
self._client.remove_topic_callback("{0}/feeds/{1}".format(self._user, feed_key))

def loop(self):
"""Manually process messages from Adafruit IO.
Call this method to check incoming subscription messages.
Copy link
Member

Choose a reason for hiding this comment

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

Please add a sentence here about how it will call the event handlers depending on the type of message.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressing this here: #47

if self._logger:
self._client._logger.debug("Client called on_unsubscribe")
if self.on_unsubscribe is not None:
self.on_unsubscribe(self, user_data, topic, pid)

def add_feed_callback(self, feed_key, callback_method):
"""Executes callback_method whenever a message is
received on feed_key.
Copy link
Member

Choose a reason for hiding this comment

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

Please mention here that the method is called by loop.

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 29, 2020
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.

3 participants