forked from platypush/platypush
Added LTR559 sensor plugin and backend
This commit is contained in:
parent
80f969cfce
commit
19dc96ff1c
4 changed files with 77 additions and 0 deletions
28
platypush/backend/sensor/ltr559.py
Normal file
28
platypush/backend/sensor/ltr559.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from platypush.backend.sensor import SensorBackend
|
||||||
|
|
||||||
|
|
||||||
|
class SensorLtr559Backend(SensorBackend):
|
||||||
|
"""
|
||||||
|
Backend to poll an `LTR559 <https://shop.pimoroni.com/products/ltr-559-light-proximity-sensor-breakout>`_
|
||||||
|
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:
|
40
platypush/plugins/gpio/sensor/ltr559.py
Normal file
40
platypush/plugins/gpio/sensor/ltr559.py
Normal file
|
@ -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 <https://shop.pimoroni.com/products/ltr-559-light-proximity-sensor-breakout>`_
|
||||||
|
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:
|
|
@ -152,3 +152,10 @@ pyScss
|
||||||
|
|
||||||
# Support for GPS integration
|
# Support for GPS integration
|
||||||
# gps
|
# gps
|
||||||
|
|
||||||
|
# Support for BME280 environment sensor
|
||||||
|
# pimoroni-bme280
|
||||||
|
|
||||||
|
# Support for LTR559 light/proximity sensor
|
||||||
|
# ltr559
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -173,6 +173,8 @@ setup(
|
||||||
'Support for NFC tags': ['nfcpy>=1.0', 'ndef'],
|
'Support for NFC tags': ['nfcpy>=1.0', 'ndef'],
|
||||||
'Support for enviropHAT': ['envirophat'],
|
'Support for enviropHAT': ['envirophat'],
|
||||||
'Support for GPS': ['gps'],
|
'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 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 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']
|
# 'Support for media subtitles': ['git+https://github.com/agonzalezro/python-opensubtitles#egg=python-opensubtitles']
|
||||||
|
|
Loading…
Reference in a new issue