Pārlūkot izejas kodu

lint

pull/259/head
Juan Pablo Giménez pirms 5 gadiem
vecāks
revīzija
b5eb6999f7
4 mainītis faili ar 81 papildinājumiem un 31 dzēšanām
  1. +16
    -0
      .pre-commit-config.yaml
  2. +51
    -22
      modules/base_plugins/gpio_actor/__init__.py
  3. +3
    -0
      requirements-dev.txt
  4. +11
    -9
      requirements.txt

+ 16
- 0
.pre-commit-config.yaml Parādīt failu

@@ -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]

+ 51
- 22
modules/base_plugins/gpio_actor/__init__.py Parādīt failu

@@ -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):


+ 3
- 0
requirements-dev.txt Parādīt failu

@@ -0,0 +1,3 @@
coverage==5.2.1
pre-commit
pylint

+ 11
- 9
requirements.txt Parādīt failu

@@ -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

Notiek ielāde…
Atcelt
Saglabāt