From 0e3873eaf3545f6ae6ab665dc77e999643c63e33 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 12 Jun 2018 00:00:15 +0200 Subject: [PATCH] Removed light sensor backend. As most of them are analog sensors, they can't communicate directly with the Raspberry - instead a plugin like serial (e.g. Arduino) or MCP3008 should act as a proxy --- platypush/backend/sensor/light/__init__.py | 50 ---------------------- 1 file changed, 50 deletions(-) delete mode 100644 platypush/backend/sensor/light/__init__.py diff --git a/platypush/backend/sensor/light/__init__.py b/platypush/backend/sensor/light/__init__.py deleted file mode 100644 index 1a8276e619..0000000000 --- a/platypush/backend/sensor/light/__init__.py +++ /dev/null @@ -1,50 +0,0 @@ -import time - -import RPi.GPIO as gpio - -from platypush.backend import Backend -from platypush.message.event.sensor.light import LightOnEvent, LightOffEvent - - -class SensorLightBackend(Backend): - state = None - - def __init__(self, pin, threshold=0.5, poll_seconds=0.5, **kwargs): - super().__init__(**kwargs) - - self.pin = pin - self.threshold = threshold - self.poll_seconds = poll_seconds - - def send_message(self, msg): - pass - - def get_state(self): - return self.state - - def run(self): - super().run() - - gpio.setmode(gpio.BCM) - gpio.setup(self.pin, gpio.IN) - self.logger.info('Initialized light sensor backend on pin {}'.format(self.pin)) - - try: - while not self.should_stop(): - value = float(gpio.input(self.pin)) - new_state = True if value >= self.threshold else False - - if self.state is not None and new_state != self.state: - if new_state is True: - self.bus.post(LightOnEvent()) - else: - self.bus.post(LightOffEvent()) - - self.state = new_state - time.sleep(self.poll_seconds) - finally: - gpio.cleanup() - - -# vim:sw=4:ts=4:et: -