From 78d44364cf4f6db4d652e947b59ba0c06d6ee395 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 12 Jan 2019 01:58:35 +0100 Subject: [PATCH] Casting data to number whenever possible on FeedUpdateEvent as well --- platypush/backend/adafruit/io.py | 2 ++ platypush/plugins/adafruit/io.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/platypush/backend/adafruit/io.py b/platypush/backend/adafruit/io.py index 38f278d1..0a791350 100644 --- a/platypush/backend/adafruit/io.py +++ b/platypush/backend/adafruit/io.py @@ -61,6 +61,8 @@ class AdafruitIoBackend(Backend): def on_message(self): def _handler(client, feed, data): + try: data = float(data) + except: pass self.bus.post(FeedUpdateEvent(feed=feed, data=data)) return _handler diff --git a/platypush/plugins/adafruit/io.py b/platypush/plugins/adafruit/io.py index 9d6a36a6..27e8b2a0 100644 --- a/platypush/plugins/adafruit/io.py +++ b/platypush/plugins/adafruit/io.py @@ -182,7 +182,8 @@ class AdafruitIoPlugin(Plugin): return [ { - attr: self._cast_value(value) if attr == 'value' else getattr(i, attr) + attr: self._cast_value(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 data ]