From b5eb6999f7c7d08eb2fcc825ea13fe5305e906f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Gim=C3=A9nez?= Date: Mon, 3 Aug 2020 22:09:43 -0300 Subject: [PATCH] lint --- .pre-commit-config.yaml | 16 +++++ modules/base_plugins/gpio_actor/__init__.py | 73 ++++++++++++++------- requirements-dev.txt | 3 + requirements.txt | 20 +++--- 4 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 requirements-dev.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..67017dc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/pycqa/pylint + rev: pylint-2.5.3 + hooks: + - id: pylint + stages: [commit] + additional_dependencies: [pylint-flask] diff --git a/modules/base_plugins/gpio_actor/__init__.py b/modules/base_plugins/gpio_actor/__init__.py index e7726b4..efeb0cc 100644 --- a/modules/base_plugins/gpio_actor/__init__.py +++ b/modules/base_plugins/gpio_actor/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +""" base gpio actors """ import time from modules import cbpi @@ -6,19 +7,25 @@ from modules.core.hardware import ActorBase, SensorPassive, SensorActive from modules.core.props import Property try: - import RPi.GPIO as GPIO + import RPi.GPIO as GPIO # pylint: disable=import-error GPIO.setmode(GPIO.BCM) -except Exception as e: - print(e) - pass - +except ModuleNotFoundError as exp: + print(exp) @cbpi.actor class GPIOSimple(ActorBase): - - gpio = Property.Select("GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27], description="GPIO to which the actor is connected") + """ + Simple GPIO Actor + """ + gpio = Property.Select("GPIO", + options=[ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27 + ], + description="GPIO to which the actor is connected") def init(self): GPIO.setup(int(self.gpio), GPIO.OUT) @@ -32,20 +39,28 @@ class GPIOSimple(ActorBase): print("GPIO OFF") GPIO.output(int(self.gpio), 0) + @cbpi.actor class GPIOPWM(ActorBase): - - gpio = Property.Select("GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27], description="GPIO to which the actor is connected") + """ + GPIO Actor with PWM support + """ + gpio = Property.Select("GPIO", + options=[ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27 + ], + description="GPIO to which the actor is connected") frequency = Property.Number("Frequency (Hz)", configurable=True) - p = None + gpio_inst = None power = 100 # duty cycle def init(self): GPIO.setup(int(self.gpio), GPIO.OUT) GPIO.output(int(self.gpio), 0) - def on(self, power=None): if power is not None: self.power = int(power) @@ -53,29 +68,37 @@ class GPIOPWM(ActorBase): if self.frequency is None: self.frequency = 0.5 # 2 sec - self.p = GPIO.PWM(int(self.gpio), float(self.frequency)) - self.p.start(int(self.power)) + self.gpio_inst = GPIO.PWM(int(self.gpio), float(self.frequency)) + self.gpio_inst.start(int(self.power)) def set_power(self, power): ''' Optional: Set the power of your actor :param power: int value between 0 - 100 - :return: + :return: ''' - if self.p: + if self.gpio_inst: if power is not None: self.power = int(power) - self.p.ChangeDutyCycle(self.power) + self.gpio_inst.ChangeDutyCycle(self.power) def off(self): print("GPIO OFF") - self.p.stop() + self.gpio_inst.stop() @cbpi.actor class RelayBoard(ActorBase): - - gpio = Property.Select("GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27], description="GPIO to which the actor is connected") + """ + Relay board Actor + """ + gpio = Property.Select("GPIO", + options=[ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27 + ], + description="GPIO to which the actor is connected") def init(self): GPIO.setup(int(self.gpio), GPIO.OUT) @@ -89,24 +112,30 @@ class RelayBoard(ActorBase): GPIO.output(int(self.gpio), 1) + @cbpi.actor class Dummy(ActorBase): - + """ + Simple Dummy Actor + """ def on(self, power=100): ''' Code to switch on the actor :param power: int value between 0 - 100 - :return: + :return: ''' print("ON") def off(self): print("OFF") + @cbpi.actor class DummyPWM(ActorBase): - + """ + Dummy Actor with PWM support + """ power = 100 def on(self, power=100): diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..a82b166 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +coverage==5.2.1 +pre-commit +pylint diff --git a/requirements.txt b/requirements.txt index 91b52cf..df1e105 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,25 @@ -attrs==19.3.0 -certifi==2020.6.20 -chardet==3.0.4 -click==7.1.2 -coverage==5.2.1 Flask==1.1.2 Flask-Classy==0.6.10 Flask-SocketIO==2.6.2 -gitdb==4.0.5 -GitPython==3.1.7 greenlet==0.4.16 + +python-engineio==3.8.2.post1 +python-socketio==1.4.4 + +attrs==19.3.0 +certifi==2020.6.20 +chardet==3.0.4 +click==7.1.2 idna==2.10 itsdangerous==1.1.0 Jinja2==2.11.2 MarkupSafe==1.1.1 -python-engineio==3.8.2.post1 -python-socketio==1.4.4 PyYAML==5.3.1 requests==2.24.0 six==1.15.0 smmap==3.0.4 urllib3==1.25.10 Werkzeug==1.0.1 + +gitdb==4.0.5 +GitPython==3.1.7