diff --git a/mopidy_raspberry_gpio/__init__.py b/mopidy_raspberry_gpio/__init__.py index f449cb7..99adcb6 100644 --- a/mopidy_raspberry_gpio/__init__.py +++ b/mopidy_raspberry_gpio/__init__.py @@ -29,4 +29,5 @@ class Extension(ext.Extension): def setup(self, registry): from .frontend import RaspberryGPIOFrontend + registry.add("frontend", RaspberryGPIOFrontend) diff --git a/mopidy_raspberry_gpio/frontend.py b/mopidy_raspberry_gpio/frontend.py index 2be9e50..fb730fd 100644 --- a/mopidy_raspberry_gpio/frontend.py +++ b/mopidy_raspberry_gpio/frontend.py @@ -12,6 +12,7 @@ class RaspberryGPIOFrontend(pykka.ThreadingActor, core.CoreListener): def __init__(self, config, core): super().__init__() import RPi.GPIO as GPIO + self.core = core self.config = config["raspberry-gpio"] self.pin_settings = {} @@ -30,20 +31,18 @@ class RaspberryGPIOFrontend(pykka.ThreadingActor, core.CoreListener): pull = GPIO.PUD_UP edge = GPIO.FALLING - if settings.active == 'active_high': + if settings.active == "active_high": pull = GPIO.PUD_DOWN edge = GPIO.RISING - GPIO.setup( - pin, - GPIO.IN, - pull_up_down=pull) + GPIO.setup(pin, GPIO.IN, pull_up_down=pull) GPIO.add_event_detect( pin, edge, callback=self.gpio_event, - bouncetime=settings.bouncetime) + bouncetime=settings.bouncetime, + ) self.pin_settings[pin] = settings diff --git a/mopidy_raspberry_gpio/pinconfig.py b/mopidy_raspberry_gpio/pinconfig.py index 9e59ebc..9ed9e9c 100644 --- a/mopidy_raspberry_gpio/pinconfig.py +++ b/mopidy_raspberry_gpio/pinconfig.py @@ -4,8 +4,7 @@ from mopidy import config class PinConfig(config.ConfigValue): - tuple_pinconfig = namedtuple("PinConfig", - ("event", "active", "bouncetime")) + tuple_pinconfig = namedtuple("PinConfig", ("event", "active", "bouncetime")) valid_events = "play_pause", "prev", "next", "volume_up", "volume_down" @@ -21,7 +20,7 @@ class PinConfig(config.ConfigValue): value = config.decode(value).strip() try: - event, active, bouncetime = value.split(',') + event, active, bouncetime = value.split(",") except ValueError: return None @@ -52,5 +51,6 @@ class PinConfig(config.ConfigValue): if value is None: return "" value = "{:s},{:s},{:d}".format( - value.event, value.active, value.bouncetime) + value.event, value.active, value.bouncetime + ) return config.encode(value) diff --git a/setup.py b/setup.py index fc1f76c..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,3 @@ from setuptools import setup -setup() \ No newline at end of file +setup() diff --git a/tests/test_frontend.py b/tests/test_frontend.py index f3a1f3f..8133fcb 100644 --- a/tests/test_frontend.py +++ b/tests/test_frontend.py @@ -19,8 +19,8 @@ dummy_config = { def test_get_frontend_classes(): - sys.modules['RPi'] = mock.Mock() - sys.modules['RPi.GPIO'] = mock.Mock() + sys.modules["RPi"] = mock.Mock() + sys.modules["RPi.GPIO"] = mock.Mock() ext = Extension() registry = mock.Mock() @@ -28,14 +28,15 @@ def test_get_frontend_classes(): ext.setup(registry) registry.add.assert_called_once_with( - 'frontend', frontend_lib.RaspberryGPIOFrontend) + "frontend", frontend_lib.RaspberryGPIOFrontend + ) def test_frontend_handler_dispatch(): - sys.modules['RPi'] = mock.Mock() - sys.modules['RPi.GPIO'] = mock.Mock() + sys.modules["RPi"] = mock.Mock() + sys.modules["RPi.GPIO"] = mock.Mock() frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, mock.Mock()) with pytest.raises(RuntimeError): - frontend.dispatch_input('tomato') + frontend.dispatch_input("tomato")