From ca855fce5d0989841c230a71b4d153c199141571 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 12 Jan 2019 01:38:17 +0100 Subject: [PATCH] Improved Adafruit IO data handling --- platypush/backend/adafruit/io.py | 2 ++ platypush/plugins/adafruit/io.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/platypush/backend/adafruit/io.py b/platypush/backend/adafruit/io.py index 10eb2a9af..38f278d17 100644 --- a/platypush/backend/adafruit/io.py +++ b/platypush/backend/adafruit/io.py @@ -49,6 +49,8 @@ class AdafruitIoBackend(Backend): def on_connect(self): def _handler(client): + for feed in self.feeds: + client.subscribe(feed) self.bus.post(ConnectedEvent()) return _handler diff --git a/platypush/plugins/adafruit/io.py b/platypush/plugins/adafruit/io.py index c54d61a37..4c83afb97 100644 --- a/platypush/plugins/adafruit/io.py +++ b/platypush/plugins/adafruit/io.py @@ -191,10 +191,17 @@ class AdafruitIoPlugin(Plugin): except ValueError: pass return value - values = [i.value for i in self.aio.data(feed)] - if limit: - return values[-limit:] - return values + from Adafruit_IO.model import DATA_FIELDS + + values = [ + { + attr: float(getattr(i, attr)) if attr == 'value' else getattr(i, attr) + for attr in DATA_FIELDS if getattr(i, attr) is not None + } + for i in self.aio.data(feed) + ] + + return values[:limit] if limit else values @action def delete(self, feed, data_id):