2018-09-06 03:02:16 +02:00
|
|
|
from platypush.backend.sensor import SensorBackend
|
|
|
|
from platypush.context import get_plugin
|
|
|
|
|
|
|
|
|
|
|
|
class SensorDistanceBackend(SensorBackend):
|
|
|
|
"""
|
|
|
|
Backend to poll a distance sensor.
|
|
|
|
|
|
|
|
Requires:
|
|
|
|
|
|
|
|
* ``RPi.GPIO`` (``pip install RPi.GPIO``)
|
|
|
|
* The :mod:`platypush.plugins.gpio.sensor.distance` plugin configured
|
2021-09-16 17:53:40 +02:00
|
|
|
|
|
|
|
Triggers:
|
|
|
|
|
|
|
|
* :class:`platypush.message.event.sensor.SensorDataChangeEvent` if the measurements of a sensor have changed
|
|
|
|
* :class:`platypush.message.event.sensor.SensorDataAboveThresholdEvent` if the measurements of a sensor have
|
|
|
|
gone above a configured threshold
|
|
|
|
* :class:`platypush.message.event.sensor.SensorDataBelowThresholdEvent` if the measurements of a sensor have
|
|
|
|
gone below a configured threshold
|
|
|
|
|
2018-09-06 03:02:16 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_measurement(self):
|
|
|
|
""" get_measurement implementation """
|
|
|
|
plugin = get_plugin('gpio.sensor.distance')
|
2018-09-06 03:14:11 +02:00
|
|
|
return {"distance": plugin.get_data().output }
|
2018-09-06 03:02:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|
|
|
|
|
|
|
|
|