From 19dc96ff1c23663ae0ee5cb7f877256fe0379946 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 14 Aug 2019 21:27:25 +0200 Subject: [PATCH] Added LTR559 sensor plugin and backend --- platypush/backend/sensor/ltr559.py | 28 +++++++++++++++++ platypush/plugins/gpio/sensor/ltr559.py | 40 +++++++++++++++++++++++++ requirements.txt | 7 +++++ setup.py | 2 ++ 4 files changed, 77 insertions(+) create mode 100644 platypush/backend/sensor/ltr559.py create mode 100644 platypush/plugins/gpio/sensor/ltr559.py diff --git a/platypush/backend/sensor/ltr559.py b/platypush/backend/sensor/ltr559.py new file mode 100644 index 000000000..193e5188a --- /dev/null +++ b/platypush/backend/sensor/ltr559.py @@ -0,0 +1,28 @@ +from platypush.backend.sensor import SensorBackend + + +class SensorLtr559Backend(SensorBackend): + """ + Backend to poll an `LTR559 `_ + light/proximity sensor + + Requires: + + * ``ltr559`` (``pip install ltr559``) + """ + + def __init__(self, light=True, proximity=True, **kwargs): + """ + :param light: Enable light sensor + :param proximity: Enable proximity sensor + """ + + enabled_sensors = { + 'light': light, + 'proximity': proximity, + } + + super().__init__(plugin='gpio.sensor.bme280', enabled_sensors=enabled_sensors, **kwargs) + + +# vim:sw=4:ts=4:et: diff --git a/platypush/plugins/gpio/sensor/ltr559.py b/platypush/plugins/gpio/sensor/ltr559.py new file mode 100644 index 000000000..acdaf5f16 --- /dev/null +++ b/platypush/plugins/gpio/sensor/ltr559.py @@ -0,0 +1,40 @@ +from platypush.plugins import action +from platypush.plugins.gpio.sensor import GpioSensorPlugin + + +class GpioSensorLtr559Plugin(GpioSensorPlugin): + """ + Plugin to interact with an `LTR559 `_ + light and proximity sensor + + Requires: + + * ``ltr559`` (``pip install ltr559``) + """ + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + # noinspection PyUnresolvedReferences + @action + def get_measurement(self): + """ + :returns: dict. Example:: + + output = { + "light": 109.3543, # Lux + "proximity": 103 # The higher the value, the nearest the object, within a ~5cm range + } + + """ + + import ltr559 + ltr559.set_proximity_active() + + return { + 'light': ltr559.get_lux(), + 'proximity': ltr559.get_proximity(), + } + + +# vim:sw=4:ts=4:et: diff --git a/requirements.txt b/requirements.txt index 2c30716d1..1d5f9d887 100644 --- a/requirements.txt +++ b/requirements.txt @@ -152,3 +152,10 @@ pyScss # Support for GPS integration # gps + +# Support for BME280 environment sensor +# pimoroni-bme280 + +# Support for LTR559 light/proximity sensor +# ltr559 + diff --git a/setup.py b/setup.py index 9a151da5b..c87e386cf 100755 --- a/setup.py +++ b/setup.py @@ -173,6 +173,8 @@ setup( 'Support for NFC tags': ['nfcpy>=1.0', 'ndef'], 'Support for enviropHAT': ['envirophat'], 'Support for GPS': ['gps'], + 'Support for BME280 environment sensor': ['pimoroni-bme280'], + 'Support for LTR559 light/proximity sensor': ['ltr559'], # 'Support for Leap Motion backend': ['git+ssh://git@github.com:BlackLight/leap-sdk-python3.git'], # 'Support for Flic buttons': ['git+https://@github.com/50ButtonsEach/fliclib-linux-hci.git'] # 'Support for media subtitles': ['git+https://github.com/agonzalezro/python-opensubtitles#egg=python-opensubtitles']