diff --git a/.travis.yml b/.travis.yml index 5ddebf978e861851dfde2ef8ecaebed848297f30..715e3282124ebbb7df9aa55ec322b0d0b0847ef2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,11 @@ stages: if: tag =~ ^\d+\.\d+\.\d+$ install: - - pip install tox + - pip install tox black jobs: include: - - python: 2.7 + - python: 3.6 stage: test script: tox -e py27 @@ -21,7 +21,7 @@ jobs: - stage: publish script: skip - python: 2.7 + python: 3.6 deploy: provider: pypi user: flyte diff --git a/pi_mqtt_gpio/modules/__init__.py b/pi_mqtt_gpio/modules/__init__.py index ed7161c3fc45a3dadf8f68a86e6a8894a3d19201..0661d99894ca2e5746fa7a32a2e91a1372c4d73c 100644 --- a/pi_mqtt_gpio/modules/__init__.py +++ b/pi_mqtt_gpio/modules/__init__.py @@ -7,7 +7,7 @@ from time import sleep BASE_SCHEMA = { "name": {"required": True, "empty": False}, "module": {"required": True, "empty": False}, - "cleanup": {"required": False, "type": "boolean", "default": True} + "cleanup": {"required": False, "type": "boolean", "default": True}, } diff --git a/pi_mqtt_gpio/modules/gpiod.py b/pi_mqtt_gpio/modules/gpiod.py index 25450b5541cddba4feba9e9bebd9fd2af2f8c715..fa9de11d067e2d8b21238757f22a202fe775b36d 100644 --- a/pi_mqtt_gpio/modules/gpiod.py +++ b/pi_mqtt_gpio/modules/gpiod.py @@ -1,5 +1,4 @@ -from pi_mqtt_gpio.modules import GenericGPIO, PinDirection, PinPullup, \ - InterruptEdge +from pi_mqtt_gpio.modules import GenericGPIO, PinDirection, PinPullup, InterruptEdge import threading import queue @@ -9,11 +8,7 @@ from datetime import datetime, timedelta REQUIREMENTS = ("gpiod",) CONFIG_SCHEMA = { - "chip": { - "type": "string", - "required": False, - "default": "/dev/gpiochip0" - } + "chip": {"type": "string", "required": False, "default": "/dev/gpiochip0"} } DIRECTIONS = None @@ -21,6 +16,7 @@ PULLUPS = None INTERRUPT = None GPIO_INTERRUPT_CALLBACK_LOOKUP = {} + class GPIO(GenericGPIO): """ Implementation of GPIO class for libgpiod (linux kernel >= 4.8). @@ -34,12 +30,15 @@ class GPIO(GenericGPIO): self.chip = gpio.chip(config["chip"]) self.pins = {} - DIRECTIONS = {PinDirection.INPUT: gpio.line_request.DIRECTION_INPUT, PinDirection.OUTPUT: gpio.line_request.DIRECTION_OUTPUT} + DIRECTIONS = { + PinDirection.INPUT: gpio.line_request.DIRECTION_INPUT, + PinDirection.OUTPUT: gpio.line_request.DIRECTION_OUTPUT, + } INTERRUPT = { InterruptEdge.RISING: gpio.line_request.EVENT_RISING_EDGE, InterruptEdge.FALLING: gpio.line_request.EVENT_FALLING_EDGE, - InterruptEdge.BOTH: gpio.line_request.EVENT_BOTH_EDGES + InterruptEdge.BOTH: gpio.line_request.EVENT_BOTH_EDGES, } def setup_pin(self, pin, direction, pullup, pin_config): @@ -50,13 +49,13 @@ class GPIO(GenericGPIO): pullup: pullup settings are not supported """ # Pullup settings are called bias in libgpiod and are only - # available since Linux Kernel 5.5. They are as of now not + # available since Linux Kernel 5.5. They are as of now not # yet part of python3-gpiod. line = self.chip.get_line(pin) config = self.io.line_request() - config.consumer = 'pi-mqtt-gpio' + config.consumer = "pi-mqtt-gpio" config.request_type = DIRECTIONS[direction] line.request(config) @@ -73,15 +72,22 @@ class GPIO(GenericGPIO): """ config = self.io.line_request() - config.consumer = 'pi-mqtt-gpio' + config.consumer = "pi-mqtt-gpio" config.request_type = INTERRUPT[edge] - t = GpioThread(chip=self.chip, offset=pin, config=config, - callback=self.interrupt_callback, bouncetime=bouncetime) + t = GpioThread( + chip=self.chip, + offset=pin, + config=config, + callback=self.interrupt_callback, + bouncetime=bouncetime, + ) t.start() - self.GPIO_INTERRUPT_CALLBACK_LOOKUP[pin] = {"handle": handle, - "callback": callback} + self.GPIO_INTERRUPT_CALLBACK_LOOKUP[pin] = { + "handle": handle, + "callback": callback, + } def set_pin(self, pin, value): offset = pin @@ -94,6 +100,7 @@ class GPIO(GenericGPIO): def cleanup(self): pass + class GpioThread(threading.Thread): def __init__(self, chip, offset, config, callback, bouncetime): super().__init__() diff --git a/tox.ini b/tox.ini index 4c3a6e7954b5b1e7c31ab4afa28e4a91f764cc1d..11b14f695fb359ceb4cc596fd2c6eeb94740f1e1 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ setenv = PYTHONPATH = {toxinidir} whitelist_externals = make + black commands = make schema py.test -m "not hw_raspberrypi and not mqtt" \ No newline at end of file