2018-07-06 02:08:38 +02:00
|
|
|
from platypush.plugins import Plugin, action
|
2018-04-13 15:49:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GpioSensorPlugin(Plugin):
|
2018-06-25 00:49:45 +02:00
|
|
|
"""
|
|
|
|
GPIO sensor abstract plugin. Any plugin that interacts with sensor via GPIO
|
|
|
|
should implement this class (and the get_measurement() method)
|
|
|
|
"""
|
|
|
|
|
2019-08-14 19:49:19 +02:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
2018-04-13 15:49:10 +02:00
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
@action
|
2018-04-13 15:49:10 +02:00
|
|
|
def get_measurement(self, *args, **kwargs):
|
2018-06-25 00:49:45 +02:00
|
|
|
"""
|
|
|
|
Implemented by the subclasses.
|
|
|
|
|
|
|
|
:returns: Either a raw scalar:
|
|
|
|
|
|
|
|
``output = 273.16``
|
|
|
|
|
|
|
|
or a name-value dictionary with the values that have been read::
|
|
|
|
|
|
|
|
output = {
|
|
|
|
"temperature": 21.5,
|
|
|
|
"humidity": 41.0
|
|
|
|
}
|
|
|
|
"""
|
2018-04-13 15:49:10 +02:00
|
|
|
raise NotImplementedError('get_measurement should be implemented in a derived class')
|
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
@action
|
2018-06-12 00:46:51 +02:00
|
|
|
def get_data(self, *args, **kwargs):
|
2018-06-25 00:49:45 +02:00
|
|
|
"""
|
|
|
|
Alias for ``get_measurement``
|
|
|
|
"""
|
|
|
|
|
2018-07-06 03:38:07 +02:00
|
|
|
return self.get_measurement(*args, **kwargs).output
|
2018-04-13 15:49:10 +02:00
|
|
|
|
2019-12-21 13:09:44 +01:00
|
|
|
@action
|
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
2018-04-13 15:49:10 +02:00
|
|
|
|
2019-12-20 21:24:47 +01:00
|
|
|
# vim:sw=4:ts=4:et:
|