diff --git a/platypush/backend/sensor/ltr559/__init__.py b/platypush/backend/sensor/ltr559/__init__.py deleted file mode 100644 index c5ae8b35..00000000 --- a/platypush/backend/sensor/ltr559/__init__.py +++ /dev/null @@ -1,37 +0,0 @@ -from platypush.backend.sensor import SensorBackend - - -class SensorLtr559Backend(SensorBackend): - """ - Backend to poll an `LTR559 `_ - light/proximity sensor - - Requires: - - * ``ltr559`` (``pip install ltr559``) - - 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 - - """ - - 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.ltr559', enabled_sensors=enabled_sensors, **kwargs) - - -# vim:sw=4:ts=4:et: diff --git a/platypush/backend/sensor/ltr559/manifest.yaml b/platypush/backend/sensor/ltr559/manifest.yaml deleted file mode 100644 index 0cd07a51..00000000 --- a/platypush/backend/sensor/ltr559/manifest.yaml +++ /dev/null @@ -1,13 +0,0 @@ -manifest: - events: - platypush.message.event.sensor.SensorDataAboveThresholdEvent: if the measurements - of a sensor havegone above a configured threshold - platypush.message.event.sensor.SensorDataBelowThresholdEvent: if the measurements - of a sensor havegone below a configured threshold - platypush.message.event.sensor.SensorDataChangeEvent: if the measurements of a - sensor have changed - install: - pip: - - ltr559 - package: platypush.backend.sensor.ltr559 - type: backend diff --git a/platypush/plugins/gpio/sensor/ltr559/__init__.py b/platypush/plugins/gpio/sensor/ltr559/__init__.py deleted file mode 100644 index 2ed58b81..00000000 --- a/platypush/plugins/gpio/sensor/ltr559/__init__.py +++ /dev/null @@ -1,41 +0,0 @@ -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): - import ltr559 - super().__init__(**kwargs) - self.ltr = ltr559.LTR559() - - # noinspection PyUnresolvedReferences - @action - def get_measurement(self): - """ - :returns: dict. Example: - - .. code-block:: python - - output = { - "light": 109.3543, # Lux - "proximity": 103 # The higher the value, the nearest the object, within a ~5cm range - } - - """ - self.ltr.update_sensor() - return { - 'light': self.ltr.get_lux(), - 'proximity': self.ltr.get_proximity(), - } - - -# vim:sw=4:ts=4:et: diff --git a/platypush/plugins/gpio/sensor/ltr559/manifest.yaml b/platypush/plugins/gpio/sensor/ltr559/manifest.yaml deleted file mode 100644 index 28740526..00000000 --- a/platypush/plugins/gpio/sensor/ltr559/manifest.yaml +++ /dev/null @@ -1,7 +0,0 @@ -manifest: - events: {} - install: - pip: - - ltr559 - package: platypush.plugins.gpio.sensor.ltr559 - type: plugin diff --git a/platypush/plugins/sensor/ltr559/__init__.py b/platypush/plugins/sensor/ltr559/__init__.py new file mode 100644 index 00000000..840ffed6 --- /dev/null +++ b/platypush/plugins/sensor/ltr559/__init__.py @@ -0,0 +1,93 @@ +from typing import Dict, List + +from typing_extensions import override + +from platypush.common.sensors import Numeric +from platypush.entities.devices import Device +from platypush.entities.distance import DistanceSensor +from platypush.entities.illuminance import IlluminanceSensor +from platypush.plugins import action +from platypush.plugins.sensor import SensorPlugin + + +# pylint: disable=too-many-ancestors +class SensorLtr559Plugin(SensorPlugin): + """ + Plugin to interact with an `LTR559 `_ + light and proximity sensor + + Requires: + + * ``ltr559`` (``pip install ltr559``) + + Triggers: + + * :class:`platypush.message.event.sensor.SensorDataAboveThresholdEvent` + * :class:`platypush.message.event.sensor.SensorDataBelowThresholdEvent` + * :class:`platypush.message.event.sensor.SensorDataChangeEvent` + + """ + + def __init__(self, **kwargs): + import ltr559 + + super().__init__(**kwargs) + self.ltr = ltr559.LTR559() + + @override + @action + def get_measurement(self, *_, **__): + """ + :returns: dict. Example: + + .. code-block:: python + + output = { + "light": 109.3543, # Lux + "proximity": 103 # The higher the value, the nearest the object, within a ~5cm range + } + + """ + self.ltr.update_sensor() + return { + 'light': self.ltr.get_lux(), + 'proximity': self.ltr.get_proximity(), + } + + @override + def transform_entities(self, entities: Dict[str, Numeric]) -> List[Device]: + sensors = [] + + if entities.get('light') is not None: + sensors.append( + IlluminanceSensor( + id='ltr559:illuminance', + name='illuminance', + value=entities['light'], + unit='lux', + ) + ) + + if entities.get('proximity') is not None: + sensors.append( + DistanceSensor( + id='ltr559:proximity', + name='proximity', + value=entities['proximity'], + unit='mm', + ) + ) + + if not sensors: + return [] + + return [ + Device( + id='ltr559', + name='LTR559 Sensor', + children=sensors, + ) + ] + + +# vim:sw=4:ts=4:et: diff --git a/platypush/plugins/sensor/ltr559/manifest.yaml b/platypush/plugins/sensor/ltr559/manifest.yaml new file mode 100644 index 00000000..6ec27a59 --- /dev/null +++ b/platypush/plugins/sensor/ltr559/manifest.yaml @@ -0,0 +1,10 @@ +manifest: + events: + platypush.message.event.sensor.SensorDataAboveThresholdEvent: + platypush.message.event.sensor.SensorDataBelowThresholdEvent: + platypush.message.event.sensor.SensorDataChangeEvent: + install: + pip: + - ltr559 + package: platypush.plugins.sensor.ltr559 + type: plugin