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 on_connect(self):
def _handler(client): def _handler(client):
for feed in self.feeds:
client.subscribe(feed)
self.bus.post(ConnectedEvent()) self.bus.post(ConnectedEvent())
return _handler return _handler

View File

@ -191,10 +191,17 @@ class AdafruitIoPlugin(Plugin):
except ValueError: pass except ValueError: pass
return value return value
values = [i.value for i in self.aio.data(feed)] from Adafruit_IO.model import DATA_FIELDS
if limit:
return values[-limit:] values = [
return 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 @action
def delete(self, feed, data_id): def delete(self, feed, data_id):