diff --git a/docs/source/platypush/plugins/adafruit.io.rst b/docs/source/platypush/plugins/adafruit.io.rst new file mode 100644 index 00000000..f3853bba --- /dev/null +++ b/docs/source/platypush/plugins/adafruit.io.rst @@ -0,0 +1,6 @@ +``platypush.plugins.adafruit.io`` +================================= + +.. automodule:: platypush.plugins.adafruit.io + :members: + diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index f3dc2689..4c2f70b1 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -5,6 +5,7 @@ Plugins :maxdepth: 2 :caption: Plugins: + platypush/plugins/adafruit.io.rst platypush/plugins/assistant.google.rst platypush/plugins/assistant.google.pushtotalk.rst platypush/plugins/calendar.rst diff --git a/platypush/plugins/adafruit/io.py b/platypush/plugins/adafruit/io.py new file mode 100644 index 00000000..a9deda2a --- /dev/null +++ b/platypush/plugins/adafruit/io.py @@ -0,0 +1,88 @@ +from Adafruit_IO import Client + +from platypush.message import Message +from platypush.plugins import Plugin, action + +class AdafruitIoPlugin(Plugin): + """ + This plugin allows you to interact with the Adafruit IO + , a cloud-based message queue and storage. + You can send values to feeds on your Adafruit IO account and read the + values of those feeds as well through any device. + + Requires: + + * **adafruit-io** (``pip install adafruit-io``) + + Some example usages:: + + # Send the temperature value for a connected sensor to the "temperature" feed + { + "type": "request", + "action": "adafruit.io.send", + "args": { + "feed": "temperature", + "value": 25.0 + } + } + + # Receive the most recent temperature value + { + "type": "request", + "action": "adafruit.io.receive", + "args": { + "feed": "temperature" + } + } + """ + + def __init__(self, username, key, *args, **kwargs): + """ + :param username: Your Adafruit username + :type username: str + + :param key: Your Adafruit IO key + :type key: str + """ + + super().__init__(*args, **kwargs) + self.aio = Client(username=username, key=key) + + + @action + def send(self, feed, value): + """ + Send a value to an Adafruit IO feed + + :param feed: Feed name + :type feed: str + + :param value: Value to send + :type value: Numeric or string + """ + + self.aio.send(feed, value) + + + @action + def receive(self, feed): + """ + Receive the most recent value from an Adafruit IO feed and returns it + as a scalar (string or number) + + :param feed: Feed name + :type feed: str + """ + + value = self.aio.receive(feed).value + + try: + value = float(value) + except ValueError: + pass + + return value + + +# vim:sw=4:ts=4:et: + diff --git a/platypush/plugins/ifttt.py b/platypush/plugins/ifttt.py index c2b162b4..492810b8 100644 --- a/platypush/plugins/ifttt.py +++ b/platypush/plugins/ifttt.py @@ -16,31 +16,14 @@ class IftttPlugin(Plugin): * **requests** (``pip install requests``) - Some example usages:: + An example:: - # Execute a GET request on a JSON endpoint + # Trigger an IFTTT event named "at_home" { "type": "request", - "action": "http.request.get", + "action": "ifttt.trigger_event", "args": { - "url": "http://remote-host/api/v1/entity", - "params": { - "start": "2000-01-01" - } - } - } - - # Execute an action on another Platypush host through HTTP interface - { - "type": "request", - "action": "http.request.post", - "args": { - "url": "http://remote-host:8008/execute", - "json": { - "type": "request", - "target": "remote-host", - "action": "music.mpd.play" - } + "event_name": "at_home" } } """