Improved Adafruit IO data handling

This commit is contained in:
Fabio Manganiello 2019-01-12 01:38:17 +01:00
parent 3b6c4a836f
commit ca855fce5d
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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):