Sfoglia il codice sorgente

Merge branch 'master' of github.com:jpgimenez/craftbeerpi3

pull/258/head
Juan Pablo Gimenez 5 anni fa
parent
commit
184a939370
10 ha cambiato i file con 106 aggiunte e 45 eliminazioni
  1. +1
    -0
      .gitignore
  2. +16
    -0
      .pre-commit-config.yaml
  3. +1
    -1
      Dockerfile
  4. +1
    -1
      modules/addon/endpoints.py
  5. +54
    -25
      modules/base_plugins/gpio_actor/__init__.py
  6. +2
    -2
      modules/core/core.py
  7. +1
    -1
      modules/notification/__init__.py
  8. +1
    -1
      modules/system/endpoints.py
  9. +3
    -0
      requirements-dev.txt
  10. +26
    -14
      requirements.txt

+ 1
- 0
.gitignore Vedi File

@@ -21,3 +21,4 @@ modules/ui/package-lock.json
.python-version .python-version
upload/* upload/*
*.bak *.bak
.vscode

+ 16
- 0
.pre-commit-config.yaml Vedi File

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

+ 1
- 1
Dockerfile Vedi File

@@ -1,5 +1,5 @@
# Dockerfile for development on a pc/mac # Dockerfile for development on a pc/mac
FROM python:3.5
FROM python:3.8


EXPOSE 5000 EXPOSE 5000




+ 1
- 1
modules/addon/endpoints.py Vedi File

@@ -134,7 +134,7 @@ def plugins():
:return: :return:
""" """
response = requests.get("https://raw.githubusercontent.com/jpgimenez/craftbeerpi-plugins/master/plugins.yaml") response = requests.get("https://raw.githubusercontent.com/jpgimenez/craftbeerpi-plugins/master/plugins.yaml")
cbpi.cache["plugins"] = merge(yaml.load(response.text), cbpi.cache["plugins"])
cbpi.cache["plugins"] = merge(yaml.safe_load(response.text), cbpi.cache["plugins"])
for key, value in cbpi.cache["plugins"].items(): for key, value in cbpi.cache["plugins"].items():
value["installed"] = os.path.isdir("./modules/plugins/%s/" % (key)) value["installed"] = os.path.isdir("./modules/plugins/%s/" % (key))




+ 54
- 25
modules/base_plugins/gpio_actor/__init__.py Vedi File

@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" base gpio actors """
import time import time


from modules import cbpi from modules import cbpi
@@ -6,19 +7,25 @@ from modules.core.hardware import ActorBase, SensorPassive, SensorActive
from modules.core.props import Property from modules.core.props import Property


try: try:
import RPi.GPIO as GPIO
import RPi.GPIO as GPIO # pylint: disable=import-error


GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
except Exception as e:
print(e)
pass

except ModuleNotFoundError as exp:
print(exp)




@cbpi.actor @cbpi.actor
class GPIOSimple(ActorBase): 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): def init(self):
GPIO.setup(int(self.gpio), GPIO.OUT) GPIO.setup(int(self.gpio), GPIO.OUT)
@@ -32,20 +39,28 @@ class GPIOSimple(ActorBase):
print("GPIO OFF") print("GPIO OFF")
GPIO.output(int(self.gpio), 0) GPIO.output(int(self.gpio), 0)



@cbpi.actor @cbpi.actor
class GPIOPWM(ActorBase): 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) frequency = Property.Number("Frequency (Hz)", configurable=True)


p = None
gpio_inst = None
power = 100 # duty cycle power = 100 # duty cycle


def init(self): def init(self):
GPIO.setup(int(self.gpio), GPIO.OUT) GPIO.setup(int(self.gpio), GPIO.OUT)
GPIO.output(int(self.gpio), 0) GPIO.output(int(self.gpio), 0)



def on(self, power=None): def on(self, power=None):
if power is not None: if power is not None:
self.power = int(power) self.power = int(power)
@@ -53,29 +68,37 @@ class GPIOPWM(ActorBase):
if self.frequency is None: if self.frequency is None:
self.frequency = 0.5 # 2 sec 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): def set_power(self, power):
''' '''
Optional: Set the power of your actor Optional: Set the power of your actor
:param power: int value between 0 - 100 :param power: int value between 0 - 100
:return:
:return:
''' '''
if self.p:
if self.gpio_inst:
if power is not None: if power is not None:
self.power = int(power) self.power = int(power)
self.p.ChangeDutyCycle(self.power)
self.gpio_inst.ChangeDutyCycle(self.power)


def off(self): def off(self):
print("GPIO OFF") print("GPIO OFF")
self.p.stop()
self.gpio_inst.stop()




@cbpi.actor @cbpi.actor
class RelayBoard(ActorBase): 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): def init(self):
GPIO.setup(int(self.gpio), GPIO.OUT) GPIO.setup(int(self.gpio), GPIO.OUT)
@@ -89,24 +112,30 @@ class RelayBoard(ActorBase):


GPIO.output(int(self.gpio), 1) GPIO.output(int(self.gpio), 1)



@cbpi.actor @cbpi.actor
class Dummy(ActorBase): class Dummy(ActorBase):

"""
Simple Dummy Actor
"""


def on(self, power=100): def on(self, power=100):
''' '''
Code to switch on the actor Code to switch on the actor
:param power: int value between 0 - 100 :param power: int value between 0 - 100
:return:
:return:
''' '''
print("ON") print("ON")


def off(self): def off(self):
print("OFF") print("OFF")



@cbpi.actor @cbpi.actor
class DummyPWM(ActorBase): class DummyPWM(ActorBase):

"""
Dummy Actor with PWM support
"""
power = 100 power = 100


def on(self, power=100): def on(self, power=100):
@@ -116,12 +145,12 @@ class DummyPWM(ActorBase):
:return: :return:
''' '''
self.power = int(power) if power is not None else 100 self.power = int(power) if power is not None else 100
print "DummyPWM ON %s" % self.power
print("DummyPWM ON %s" % self.power)


def off(self): def off(self):
self.power = 100 self.power = 100
print "OFF"
print("OFF")


def set_power(self, power): def set_power(self, power):
self.power = int(power) self.power = int(power)
print "DummyPWM POWER %s" % self.power
print("DummyPWM POWER %s" % self.power)

+ 2
- 2
modules/core/core.py Vedi File

@@ -378,12 +378,12 @@ class CraftBeerPi(ActorAPI, SensorAPI):




# Event Bus # Event Bus
def event(self, name, async=False):
def event(self, name, use_async=False):


def real_decorator(function): def real_decorator(function):
if self.eventbus.get(name) is None: if self.eventbus.get(name) is None:
self.eventbus[name] = [] self.eventbus[name] = []
self.eventbus[name].append({"function": function, "async": async})
self.eventbus[name].append({"function": function, "async": use_async})
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return function(*args, **kwargs) return function(*args, **kwargs)
return wrapper return wrapper


+ 1
- 1
modules/notification/__init__.py Vedi File

@@ -24,7 +24,7 @@ class NotificationView(FlaskView):
cbpi.cache["messages"].pop(idx) cbpi.cache["messages"].pop(idx)
return ('', 204) return ('', 204)


@cbpi.event("MESSAGE", async=True)
@cbpi.event("MESSAGE", use_async=True)
def messageEvent(message, **kwargs): def messageEvent(message, **kwargs):
""" """
React on message event. add the message to the cache and push the message to the clients React on message event. add the message to the cache and push the message to the clients


+ 1
- 1
modules/system/endpoints.py Vedi File

@@ -130,8 +130,8 @@ class SystemView(FlaskView):
endpoints[rule.rule][m] = dict(summary="", description="", consumes=["application/json"],produces=["application/json"]) endpoints[rule.rule][m] = dict(summary="", description="", consumes=["application/json"],produces=["application/json"])


with open("config/version.yaml", 'r') as stream: with open("config/version.yaml", 'r') as stream:
y = yaml.safe_load(stream)


y = yaml.load(stream)
pprint.pprint(y) pprint.pprint(y)
pprint.pprint(re) pprint.pprint(re)
return Response(yaml.dump(re), mimetype='text/yaml') return Response(yaml.dump(re), mimetype='text/yaml')


+ 3
- 0
requirements-dev.txt Vedi File

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

+ 26
- 14
requirements.txt Vedi File

@@ -1,14 +1,26 @@
Flask==1.0
Flask-SocketIO==2.6.2
eventlet==0.19.0
greenlet==0.4.10
python-dateutil==2.5.3
python-engineio==3.8.2.post1
python-mimeparse==1.5.2
python-socketio==1.4.4
PyYAML==4.2b1
requests==2.20.0
Werkzeug==0.15.3
httplib2==0.18.0
flask-classy==0.6.10
GitPython
Flask==1.1.2
Flask-Classy==0.6.10
Flask-SocketIO==2.6.2
greenlet==0.4.16
eventlet==0.26.1

python-engineio==3.13.1
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
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

Loading…
Annulla
Salva