Casting data to number whenever possible on FeedUpdateEvent as well

This commit is contained in:
Fabio Manganiello 2019-01-12 01:58:35 +01:00
parent d63ad91b2a
commit 78d44364cf
2 changed files with 4 additions and 1 deletions

View file

@ -61,6 +61,8 @@ class AdafruitIoBackend(Backend):
def on_message(self): def on_message(self):
def _handler(client, feed, data): def _handler(client, feed, data):
try: data = float(data)
except: pass
self.bus.post(FeedUpdateEvent(feed=feed, data=data)) self.bus.post(FeedUpdateEvent(feed=feed, data=data))
return _handler return _handler

View file

@ -182,7 +182,8 @@ class AdafruitIoPlugin(Plugin):
return [ 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 attr in DATA_FIELDS if getattr(i, attr) is not None
} for i in data } for i in data
] ]