mirror of
https://github.com/Manuel83/craftbeerpi3
synced 2026-08-09 18:52:40 +02:00
Compare commits
55
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e960dce1c | ||
|
|
04f67754e5 | ||
|
|
bf705e3957 | ||
|
|
ecd71e8073 | ||
|
|
9f2d45d834 | ||
|
|
996bc54768 | ||
|
|
63f9f5468b | ||
|
|
16ad8daf44 | ||
|
|
67a103d1f3 | ||
|
|
274f282e11 | ||
|
|
4e432e05bd | ||
|
|
eda209422f | ||
|
|
5b47b94833 | ||
|
|
98409d9895 | ||
|
|
433b1c30f1 | ||
|
|
a477cb83a8 | ||
|
|
a22dcba77c | ||
|
|
c1d94a8f61 | ||
|
|
dd64f4ee16 | ||
|
|
1414b1ed3b | ||
|
|
acd404622b | ||
|
|
d657077570 | ||
|
|
0e6da89cfd | ||
|
|
faa2b9d32c | ||
|
|
83699f1933 | ||
|
|
fea3e85053 | ||
|
|
5efa1df350 | ||
|
|
dd5b5f456a | ||
|
|
e0e3aff929 | ||
|
|
2a02979e37 | ||
|
|
a1740074ac | ||
|
|
1b3042a082 | ||
|
|
b279dcf347 | ||
|
|
211edc1bbc | ||
|
|
b56c10a8a5 | ||
|
|
8d2c5c916a | ||
|
|
d637c08eba | ||
|
|
0447621895 | ||
|
|
03395647ed | ||
|
|
65833b1249 | ||
|
|
25ace8024c | ||
|
|
820061cf09 | ||
|
|
c1c5faa1f3 | ||
|
|
837b906af1 | ||
|
|
0f42153591 | ||
|
|
5fc5684e56 | ||
|
|
dc908268dd | ||
|
|
14e4e6d61a | ||
|
|
ae7e3a2e7b | ||
|
|
3eee952a04 | ||
|
|
88b360a8d7 | ||
|
|
3761713219 | ||
|
|
a96c678dd9 | ||
|
|
e7765a2c4c | ||
|
|
74b56937e7 |
+1
-1
@@ -4,7 +4,7 @@ craftbeerpi.db
|
||||
**/node_modules/*
|
||||
*.pyc
|
||||
*.templog
|
||||
|
||||
venv/
|
||||
modules/plugins/*
|
||||
!modules/plugins/__init__.py
|
||||
*.pyc
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
# Dockerfile for development on a pc/mac
|
||||
FROM python:2
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY requirements.txt ./
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "run.py"]
|
||||
@@ -28,6 +28,21 @@ http://web.craftbeerpi.com/hardware/
|
||||
|
||||
CraftBeerPi 3.0 is a complete rewrite. Server as well as user interface. I recommend to use a second SD card for testing.
|
||||
|
||||
## Docker-based development
|
||||
|
||||
For developing this application or its plugins on a PC/Mac you can use the docker-compose file:
|
||||
|
||||
``` shell
|
||||
$ docker-compose up
|
||||
...
|
||||
Starting craftbeerpi3_app_1 ... done
|
||||
Attaching to craftbeerpi3_app_1
|
||||
app_1 | [2018-08-13 12:54:44,264] ERROR in __init__: BUZZER not working
|
||||
app_1 | (1) wsgi starting up on http://0.0.0.0:5000
|
||||
```
|
||||
|
||||
The contents of this folder will be mounted to `/usr/src/craftbeerpi3` and the server will be accesible on `localhost:5000`.
|
||||
|
||||
## Donation
|
||||
|
||||
CraftBeerPi is a free & open source project. If you like to support the project I happy about a donation:
|
||||
|
||||
+2
-1
@@ -84,7 +84,8 @@ INSERT OR IGNORE INTO config VALUES ('actor_cols', 4, 'select', 'Adjust the widt
|
||||
INSERT OR IGNORE INTO config VALUES ('sensor_cols', 4, 'select', 'Adjust the width of a sensor widget on the brewing dashboard', '[1,2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12]');
|
||||
INSERT OR IGNORE INTO config VALUES ('unit', 'C', 'select', 'Temperature Unit', '["C","F"]');
|
||||
INSERT OR IGNORE INTO config VALUES ('brewery_name', 'My Home Brewery', 'text', 'Your brewery name', NULL );
|
||||
INSERT OR IGNORE INTO config VALUES ('buzzer', 16, 'select', 'Buzzer GPIO', '[16,17,18,19,20]');
|
||||
INSERT OR IGNORE INTO config VALUES ('buzzer', 16, 'select', 'Buzzer GPIO', '[16,17,18,19,20,21,22,23]');
|
||||
INSERT OR IGNORE INTO config VALUES ('buzzer_beep_level', 'HIGH', 'select', 'Buzzer Logic Beep Level', '["HIGH", "LOW"]');
|
||||
INSERT OR IGNORE INTO config VALUES ('setup', 'YES', 'select', 'Show the Setup dialog', '["YES","NO"]');
|
||||
INSERT OR IGNORE INTO config VALUES ('brew_name', '', 'text', 'Brew Name', NULL);
|
||||
INSERT OR IGNORE INTO config VALUES ('donation_notification', 'YES', 'select', 'Disable Donation Notification', '["YES","NO"]');
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# docker-compose file for development on a pc/mac
|
||||
version: '3.3'
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
ports:
|
||||
- 5000:5000
|
||||
volumes:
|
||||
- $PWD:/usr/src/app
|
||||
+13
-8
@@ -19,7 +19,8 @@ show_menu () {
|
||||
"7" "Software Update (git pull)" \
|
||||
"8" "Reset File Changes (git reset --hard)" \
|
||||
"9" "Clear all logs" \
|
||||
"10" "Reboot Raspberry Pi" 3>&1 1>&2 2>&3)
|
||||
"10" "Reboot Raspberry Pi" \
|
||||
"11" "Stop CraftBeerPi, Clear logs, Start CraftBeerPi" 3>&1 1>&2 2>&3)
|
||||
|
||||
BUTTON=$?
|
||||
# Exit if user pressed cancel or escape
|
||||
@@ -34,13 +35,6 @@ show_menu () {
|
||||
apt-get -y update; apt-get -y upgrade;
|
||||
fi
|
||||
|
||||
confirmAnswer "Would you like to install wiringPI? This is required to control the GPIO"
|
||||
if [ $? = 0 ]; then
|
||||
git clone git://git.drogon.net/wiringPi;
|
||||
cd wiringPi;
|
||||
./build; cd ..;
|
||||
rm -rf wiringPi;
|
||||
fi
|
||||
|
||||
apt-get -y install python-setuptools
|
||||
easy_install pip
|
||||
@@ -143,6 +137,17 @@ show_menu () {
|
||||
show_menu
|
||||
fi
|
||||
;;
|
||||
11)
|
||||
confirmAnswer "Are you sure you want to reboot CraftBeerPi and delete all log files?"
|
||||
if [ $? = 0 ]; then
|
||||
sudo /etc/init.d/craftbeerpiboot stop
|
||||
sudo rm -rf logs/*.log
|
||||
sudo /etc/init.d/craftbeerpiboot start
|
||||
show_menu
|
||||
else
|
||||
show_menu
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
+5
-12
@@ -1,16 +1,9 @@
|
||||
import json
|
||||
import pprint
|
||||
import sys, os
|
||||
from flask import Flask, render_template, redirect
|
||||
from flask_socketio import SocketIO, emit
|
||||
|
||||
import logging
|
||||
# Define the WSGI application object
|
||||
|
||||
from app_config import *
|
||||
import pprint
|
||||
|
||||
from modules.core.db import get_db
|
||||
from .app_config import *
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@@ -30,15 +23,15 @@ import modules.actor
|
||||
import modules.notification
|
||||
import modules.fermenter
|
||||
from modules.addon.endpoints import initPlugins
|
||||
import modules.ui
|
||||
import modules.system
|
||||
import modules.ui.endpoints
|
||||
import modules.system.endpoints
|
||||
import modules.buzzer
|
||||
import modules.stats
|
||||
import modules.kettle
|
||||
import modules.recipe_import
|
||||
import modules.core.db_mirgrate
|
||||
|
||||
from app_config import cbpi
|
||||
from .app_config import cbpi
|
||||
# Build the database:
|
||||
# This will create the database file using SQLAlchemy
|
||||
|
||||
@@ -47,7 +40,7 @@ pp = pprint.PrettyPrinter(indent=6)
|
||||
|
||||
|
||||
def init_db():
|
||||
print "INIT DB"
|
||||
print("INIT DB")
|
||||
with app.app_context():
|
||||
db = get_db()
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import endpoints
|
||||
@@ -134,7 +134,7 @@ def plugins():
|
||||
"""
|
||||
response = requests.get("https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml")
|
||||
cbpi.cache["plugins"] = merge(yaml.load(response.text), cbpi.cache["plugins"])
|
||||
for key, value in cbpi.cache["plugins"].iteritems():
|
||||
for key, value in cbpi.cache["plugins"].items():
|
||||
value["installed"] = os.path.isdir("./modules/plugins/%s/" % (key))
|
||||
|
||||
return json.dumps(cbpi.cache["plugins"])
|
||||
|
||||
@@ -8,8 +8,6 @@ from flask_socketio import SocketIO, emit
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
|
||||
from modules.core.core import CraftBeerPi, ActorBase, SensorBase
|
||||
from modules.core.db import DBModel
|
||||
|
||||
|
||||
@@ -165,7 +165,11 @@ class BoilStep(StepBase):
|
||||
hop_2 = Property.Number("Hop 2 Addition", configurable=True, description="Second Hop alert")
|
||||
hop_2_added = Property.Number("", default_value=None)
|
||||
hop_3 = Property.Number("Hop 3 Addition", configurable=True)
|
||||
hop_3_added = Property.Number("", default_value=None, description="Second Hop alert")
|
||||
hop_3_added = Property.Number("", default_value=None, description="Third Hop alert")
|
||||
hop_4 = Property.Number("Hop 4 Addition", configurable=True)
|
||||
hop_4_added = Property.Number("", default_value=None, description="Fourth Hop alert")
|
||||
hop_5 = Property.Number("Hop 5 Addition", configurable=True)
|
||||
hop_5_added = Property.Number("", default_value=None, description="Fives Hop alert")
|
||||
|
||||
def init(self):
|
||||
'''
|
||||
@@ -217,6 +221,8 @@ class BoilStep(StepBase):
|
||||
self.check_hop_timer(1, self.hop_1)
|
||||
self.check_hop_timer(2, self.hop_2)
|
||||
self.check_hop_timer(3, self.hop_3)
|
||||
self.check_hop_timer(4, self.hop_4)
|
||||
self.check_hop_timer(5, self.hop_5)
|
||||
# Check if timer finished and go to next step
|
||||
if self.is_timer_finished() == True:
|
||||
self.notify("Boil Step Completed!", "Starting the next step", timeout=None)
|
||||
|
||||
@@ -15,7 +15,7 @@ class DummyTempSensor(SensorActive):
|
||||
|
||||
@cbpi.action("My Custom Action")
|
||||
def my_action(self):
|
||||
print "HELLO WORLD"
|
||||
|
||||
pass
|
||||
|
||||
def get_unit(self):
|
||||
|
||||
@@ -10,7 +10,7 @@ try:
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
except Exception as e:
|
||||
print e
|
||||
print(e)
|
||||
pass
|
||||
|
||||
|
||||
@@ -25,21 +25,21 @@ class GPIOSimple(ActorBase):
|
||||
GPIO.output(int(self.gpio), 0)
|
||||
|
||||
def on(self, power=0):
|
||||
print "GPIO ON %s" % str(self.gpio)
|
||||
print("GPIO ON %s" % str(self.gpio))
|
||||
GPIO.output(int(self.gpio), 1)
|
||||
|
||||
def off(self):
|
||||
print "GPIO OFF"
|
||||
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")
|
||||
duty_cylce = Property.Number("Duty Cycle", configurable=True)
|
||||
frequency = Property.Number("Frequency (Hz)", configurable=True)
|
||||
|
||||
p = None
|
||||
power = 100
|
||||
power = 100 # duty cycle
|
||||
|
||||
def init(self):
|
||||
GPIO.setup(int(self.gpio), GPIO.OUT)
|
||||
@@ -50,10 +50,10 @@ class GPIOPWM(ActorBase):
|
||||
if power is not None:
|
||||
self.power = int(power)
|
||||
|
||||
if self.duty_cylce is None:
|
||||
duty_cylce = 50
|
||||
if self.frequency is None:
|
||||
self.frequency = 0.5 # 2 sec
|
||||
|
||||
self.p = GPIO.PWM(int(self.gpio), int(self.duty_cylce))
|
||||
self.p = GPIO.PWM(int(self.gpio), float(self.frequency))
|
||||
self.p.start(int(self.power))
|
||||
|
||||
def set_power(self, power):
|
||||
@@ -67,7 +67,7 @@ class GPIOPWM(ActorBase):
|
||||
self.p.ChangeDutyCycle(self.power)
|
||||
|
||||
def off(self):
|
||||
print "GPIO OFF"
|
||||
print("GPIO OFF")
|
||||
self.p.stop()
|
||||
|
||||
|
||||
@@ -98,10 +98,10 @@ class Dummy(ActorBase):
|
||||
:param power: int value between 0 - 100
|
||||
:return:
|
||||
'''
|
||||
print "ON"
|
||||
print("ON")
|
||||
|
||||
def off(self):
|
||||
print "OFF"
|
||||
print("OFF")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,5 @@ class Hysteresis(KettleController):
|
||||
self.heater_on(100)
|
||||
elif self.get_temp() >= self.get_target_temp() - float(self.off):
|
||||
self.heater_off()
|
||||
else:
|
||||
self.heater_off()
|
||||
self.sleep(1)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from thread import start_new_thread
|
||||
#from threading import start_new_thread
|
||||
from modules import cbpi
|
||||
|
||||
try:
|
||||
@@ -10,10 +10,11 @@ except Exception as e:
|
||||
class Buzzer(object):
|
||||
|
||||
sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
|
||||
def __init__(self, gpio):
|
||||
def __init__(self, gpio, beep_level):
|
||||
try:
|
||||
cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
|
||||
self.gpio = int(gpio)
|
||||
self.beep_level = beep_level
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(self.gpio, GPIO.OUT)
|
||||
self.state = True
|
||||
@@ -31,20 +32,26 @@ class Buzzer(object):
|
||||
try:
|
||||
for i in sound:
|
||||
if (isinstance(i, str)):
|
||||
if i == "H":
|
||||
if i == "H" and self.beep_level == "HIGH":
|
||||
GPIO.output(int(self.gpio), GPIO.HIGH)
|
||||
else:
|
||||
elif i == "H" and self.beep_level != "HIGH":
|
||||
GPIO.output(int(self.gpio), GPIO.LOW)
|
||||
elif i == "L" and self.beep_level == "HIGH":
|
||||
GPIO.output(int(self.gpio), GPIO.LOW)
|
||||
else:
|
||||
GPIO.output(int(self.gpio), GPIO.HIGH)
|
||||
else:
|
||||
time.sleep(i)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
start_new_thread(play, (self.sound,))
|
||||
## TODO
|
||||
#start_new_thread(play, (self.sound,))
|
||||
|
||||
@cbpi.initalizer(order=1)
|
||||
def init(cbpi):
|
||||
gpio = cbpi.get_config_parameter("buzzer", 16)
|
||||
cbpi.buzzer = Buzzer(gpio)
|
||||
gpio = cbpi.get_config_parameter("buzzer", 22)
|
||||
beep_level = cbpi.get_config_parameter("buzzer_beep_level", "HIGH")
|
||||
|
||||
cbpi.buzzer = Buzzer(gpio, beep_level)
|
||||
cbpi.beep()
|
||||
cbpi.app.logger.info("INIT OK")
|
||||
|
||||
@@ -46,7 +46,7 @@ class ConfigView(BaseView):
|
||||
|
||||
with cls.api.app.app_context():
|
||||
cls.api.cache[cls.cache_key] = {}
|
||||
for key, value in cls.model.get_all().iteritems():
|
||||
for key, value in cls.model.get_all().items():
|
||||
cls.post_init_callback(value)
|
||||
cls.api.cache[cls.cache_key][value.name] = value
|
||||
|
||||
|
||||
@@ -104,6 +104,6 @@ class BaseView(FlaskView):
|
||||
cls.api.cache[cls.cache_key].append(value)
|
||||
else:
|
||||
cls.api.cache[cls.cache_key] = {}
|
||||
for key, value in cls.model.get_all().iteritems():
|
||||
for key, value in cls.model.get_all().items():
|
||||
cls.post_init_callback(value)
|
||||
cls.api.cache[cls.cache_key][key] = value
|
||||
@@ -42,7 +42,7 @@ class ControllerBase(object):
|
||||
|
||||
@staticmethod
|
||||
def init_global():
|
||||
print "GLOBAL CONTROLLER INIT"
|
||||
print("GLOBAL CONTROLLER INIT")
|
||||
|
||||
def notify(self, headline, message, type="success", timeout=5000):
|
||||
self.api.notify(headline, message, type, timeout)
|
||||
@@ -139,7 +139,7 @@ class FermenterController(ControllerBase, ActorController, SensorController):
|
||||
def heater_on(self, power=100):
|
||||
f = self.api.cache.get("fermenter").get(self.fermenter_id)
|
||||
if f.heater is not None:
|
||||
self.actor_on(int(f.heater))
|
||||
self.actor_on(power, int(f.heater))
|
||||
|
||||
@cbpi.try_catch(None)
|
||||
def heater_off(self):
|
||||
|
||||
+7
-11
@@ -12,9 +12,9 @@ from time import localtime, strftime
|
||||
from functools import wraps, update_wrapper
|
||||
|
||||
|
||||
from props import *
|
||||
from .props import *
|
||||
|
||||
from hardware import *
|
||||
from .hardware import *
|
||||
|
||||
import time
|
||||
import uuid
|
||||
@@ -28,7 +28,7 @@ class ActorAPI(object):
|
||||
def init_actors(self):
|
||||
self.app.logger.info("Init Actors")
|
||||
t = self.cache.get("actor_types")
|
||||
for key, value in t.iteritems():
|
||||
for key, value in t.items():
|
||||
value.get("class").api = self
|
||||
value.get("class").init_global()
|
||||
|
||||
@@ -40,7 +40,6 @@ class ActorAPI(object):
|
||||
value = self.cache.get("actors").get(int(id))
|
||||
cfg = value.config.copy()
|
||||
cfg.update(dict(api=self, id=id, name=value.name))
|
||||
cfg.update(dict(api=self, id=id, name=value.name))
|
||||
clazz = self.cache.get("actor_types").get(value.type).get("class")
|
||||
value.instance = clazz(**cfg)
|
||||
value.instance.init()
|
||||
@@ -90,7 +89,7 @@ class SensorAPI(object):
|
||||
self.app.logger.info("Init Sensors")
|
||||
|
||||
t = self.cache.get("sensor_types")
|
||||
for key, value in t.iteritems():
|
||||
for key, value in t.items():
|
||||
value.get("class").init_global()
|
||||
|
||||
for key in self.cache.get("sensors"):
|
||||
@@ -293,7 +292,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
|
||||
t = tmpObj.__getattribute__(m)
|
||||
self.cache[key][name]["properties"].append({"name": m, "label": t.label, "type": "kettle", "configurable": t.configurable, "description": t.description})
|
||||
|
||||
for name, method in cls.__dict__.iteritems():
|
||||
for name, method in cls.__dict__.items():
|
||||
if hasattr(method, "action"):
|
||||
label = method.__getattribute__("label")
|
||||
self.cache[key][cls.__name__]["actions"].append({"method": name, "label": label})
|
||||
@@ -310,10 +309,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
|
||||
def actor2(self, description="", power=True, **options):
|
||||
|
||||
def decorator(f):
|
||||
print f()
|
||||
print f
|
||||
print options
|
||||
print description
|
||||
|
||||
return f
|
||||
return decorator
|
||||
|
||||
@@ -370,7 +366,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
|
||||
t = tmpObj.__getattribute__(m)
|
||||
self.cache[key][name]["properties"].append({"name": m, "label": t.label, "type": "kettle", "configurable": t.configurable, "description": t.description})
|
||||
|
||||
for name, method in cls.__dict__.iteritems():
|
||||
for name, method in cls.__dict__.items():
|
||||
if hasattr(method, "action"):
|
||||
label = method.__getattribute__("label")
|
||||
self.cache[key][cls.__name__]["actions"].append({"method": name, "label": label})
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ class DBModel(object):
|
||||
cur = get_db().cursor()
|
||||
|
||||
|
||||
if cls.__priamry_key__ is not None and kwargs.has_key(cls.__priamry_key__):
|
||||
if cls.__priamry_key__ is not None and cls.__priamry_key__ in kwargs:
|
||||
query = "INSERT INTO %s (%s, %s) VALUES (?, %s)" % (
|
||||
cls.__table_name__,
|
||||
cls.__priamry_key__,
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import sqlite3
|
||||
import os
|
||||
from modules import cbpi
|
||||
from db import get_db
|
||||
from .db import get_db
|
||||
|
||||
def execute_file(curernt_version, data):
|
||||
# TODO add if block
|
||||
'''
|
||||
if curernt_version >= data["version"]:
|
||||
cbpi.app.logger.info("SKIP DB FILE: %s" % data["file"])
|
||||
return
|
||||
'''
|
||||
try:
|
||||
with sqlite3.connect("craftbeerpi.db") as conn:
|
||||
with open('./update/%s' % data["file"], 'r') as f:
|
||||
@@ -19,8 +22,8 @@ def execute_file(curernt_version, data):
|
||||
conn.commit()
|
||||
|
||||
except sqlite3.OperationalError as err:
|
||||
print "EXCEPT"
|
||||
print err
|
||||
print("EXCEPT")
|
||||
print(err)
|
||||
|
||||
@cbpi.initalizer(order=-9999)
|
||||
def init(app=None):
|
||||
|
||||
@@ -40,18 +40,16 @@ class Base(object):
|
||||
|
||||
|
||||
class SensorBase(Base):
|
||||
|
||||
last_value = 0
|
||||
|
||||
def init(self):
|
||||
print "INIT Base SENSOR"
|
||||
print("INIT Base SENSOR")
|
||||
|
||||
def stop(self):
|
||||
print "STOP SENSOR"
|
||||
print("STOP SENSOR")
|
||||
|
||||
def data_received(self, data):
|
||||
|
||||
|
||||
self.last_value = data
|
||||
self.api.receive_sensor_value(self.id, data)
|
||||
|
||||
@@ -65,12 +63,11 @@ class SensorBase(Base):
|
||||
|
||||
return {"value": self.last_value, "unit": self.get_unit()}
|
||||
|
||||
class SensorActive(SensorBase):
|
||||
|
||||
class SensorActive(SensorBase):
|
||||
__running = False
|
||||
|
||||
def is_running(self):
|
||||
|
||||
return self.__running
|
||||
|
||||
def init(self):
|
||||
@@ -79,14 +76,13 @@ class SensorActive(SensorBase):
|
||||
def stop(self):
|
||||
self.__running = False
|
||||
|
||||
|
||||
def execute(self):
|
||||
pass
|
||||
|
||||
|
||||
class SensorPassive(SensorBase):
|
||||
def init(self):
|
||||
print "INIT PASSIV SENSOR"
|
||||
print("INIT PASSIV SENSOR")
|
||||
pass
|
||||
|
||||
def read(self):
|
||||
|
||||
@@ -109,10 +109,10 @@ class StepBase(Timer, ActorAPI, SensorAPI, KettleAPI):
|
||||
pass
|
||||
|
||||
def execute(self):
|
||||
print "-------------"
|
||||
print "Step Info"
|
||||
print "Kettle ID: %s" % self.kettle_id
|
||||
print "ID: %s" % self.id
|
||||
print("-------------")
|
||||
print("Step Info")
|
||||
print("Kettle ID: %s" % self.kettle_id)
|
||||
print("ID: %s" % self.id)
|
||||
|
||||
|
||||
def __init__(self, *args, **kwds):
|
||||
|
||||
@@ -77,6 +77,7 @@ class FermenterView(BaseView):
|
||||
|
||||
def _post_put_callback(self, m):
|
||||
m.state = False
|
||||
self.reset(int(m.id))
|
||||
|
||||
@route('/<int:id>/targettemp/<temp>', methods=['POST'])
|
||||
def postTargetTemp(self, id, temp):
|
||||
@@ -209,7 +210,7 @@ class FermenterView(BaseView):
|
||||
def toggle(self, id):
|
||||
fermenter = cbpi.cache.get(self.cache_key)[id]
|
||||
try:
|
||||
print fermenter.state
|
||||
print(fermenter.state)
|
||||
if fermenter.state is False:
|
||||
# Start controller
|
||||
if fermenter.logic is not None:
|
||||
@@ -222,6 +223,8 @@ class FermenterView(BaseView):
|
||||
|
||||
def run(instance):
|
||||
instance.run()
|
||||
fermenter.state = not fermenter.state
|
||||
cbpi.emit("UPDATE_FERMENTER", cbpi.cache.get(self.cache_key).get(id))
|
||||
|
||||
t = cbpi.socketio.start_background_task(target=run, instance=instance)
|
||||
fermenter.state = not fermenter.state
|
||||
@@ -233,7 +236,7 @@ class FermenterView(BaseView):
|
||||
cbpi.emit("UPDATE_FERMENTER", cbpi.cache.get(self.cache_key).get(id))
|
||||
|
||||
except Exception as e:
|
||||
print e
|
||||
print(e)
|
||||
cbpi.notify("Toogle Fementer Controller failed", "Pleae check the %s configuration" % fermenter.name,
|
||||
type="danger", timeout=None)
|
||||
return ('', 500)
|
||||
@@ -258,7 +261,7 @@ class FermenterView(BaseView):
|
||||
cbpi.emit("UPDATE_FERMENTER", cbpi.cache.get(self.cache_key)[id])
|
||||
|
||||
def check_step(self):
|
||||
for key, value in cbpi.cache["fermenter_task"].iteritems():
|
||||
for key, value in cbpi.cache["fermenter_task"].items():
|
||||
|
||||
try:
|
||||
fermenter = self.get_fermenter(key)
|
||||
@@ -289,7 +292,7 @@ def read_target_temps(api):
|
||||
:return: None
|
||||
"""
|
||||
result = {}
|
||||
for key, value in cbpi.cache.get("fermenter").iteritems():
|
||||
for key, value in cbpi.cache.get("fermenter").items():
|
||||
cbpi.save_to_file(key, value.target_temp, prefix="fermenter")
|
||||
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ def read_target_temps(api):
|
||||
:return: None
|
||||
"""
|
||||
result = {}
|
||||
for key, value in cbpi.cache.get("kettle").iteritems():
|
||||
for key, value in cbpi.cache.get("kettle").items():
|
||||
cbpi.save_to_file(key, value.target_temp, prefix="kettle")
|
||||
|
||||
@cbpi.initalizer()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import endpoints
|
||||
@@ -1,3 +0,0 @@
|
||||
import beerxml
|
||||
import kbh
|
||||
import restapi
|
||||
@@ -48,6 +48,7 @@ class BeerXMLImport(FlaskView):
|
||||
|
||||
|
||||
steps = self.getSteps(id)
|
||||
boil_time_alerts = self.getBoilAlerts(id)
|
||||
name = self.getRecipeName(id)
|
||||
self.api.set_config_parameter("brew_name", name)
|
||||
boil_time = self.getBoilTime(id)
|
||||
@@ -67,10 +68,29 @@ class BeerXMLImport(FlaskView):
|
||||
for row in steps:
|
||||
Step.insert(**{"name": row.get("name"), "type": mashstep_type, "config": {"kettle": mash_kettle, "temp": float(row.get("temp")), "timer": row.get("timer")}})
|
||||
Step.insert(**{"name": "ChilStep", "type": "ChilStep", "config": {"timer": 15}})
|
||||
## Add cooking step
|
||||
Step.insert(**{"name": "Boil", "type": boilstep_type, "config": {"kettle": boil_kettle, "temp": boil_temp, "timer": boil_time}})
|
||||
## Add boiling step
|
||||
Step.insert(**{
|
||||
"name": "Boil",
|
||||
"type": boilstep_type,
|
||||
"config": {
|
||||
"kettle": boil_kettle,
|
||||
"temp": boil_temp,
|
||||
"timer": boil_time,
|
||||
## Beer XML defines additions as the total time spent in boiling,
|
||||
## CBP defines it as time-until-alert
|
||||
|
||||
## Also, The model supports five boil-time additions.
|
||||
## Set the rest to None to signal them being absent
|
||||
"hop_1": boil_time - boil_time_alerts[0] if len(boil_time_alerts) >= 1 else None,
|
||||
"hop_2": boil_time - boil_time_alerts[1] if len(boil_time_alerts) >= 2 else None,
|
||||
"hop_3": boil_time - boil_time_alerts[2] if len(boil_time_alerts) >= 3 else None,
|
||||
"hop_4": boil_time - boil_time_alerts[3] if len(boil_time_alerts) >= 4 else None,
|
||||
"hop_5": boil_time - boil_time_alerts[4] if len(boil_time_alerts) >= 5 else None
|
||||
}
|
||||
})
|
||||
## Add Whirlpool step
|
||||
Step.insert(**{"name": "Whirlpool", "type": "ChilStep", "config": {"timer": 15}})
|
||||
StepView().reset()
|
||||
self.api.emit("UPDATE_ALL_STEPS", Step.get_all())
|
||||
self.api.notify(headline="Recipe %s loaded successfully" % name, message="")
|
||||
except Exception as e:
|
||||
@@ -87,18 +107,40 @@ class BeerXMLImport(FlaskView):
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
return float(e.find('./RECIPE[%s]/BOIL_TIME' % (str(id))).text)
|
||||
|
||||
def getBoilAlerts(self, id):
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
|
||||
recipe = e.find('./RECIPE[%s]' % (str(id)))
|
||||
alerts = []
|
||||
for e in recipe.findall('./HOPS/HOP'):
|
||||
use = e.find('USE').text
|
||||
## Hops which are not used in the boil step should not cause alerts
|
||||
if use != 'Aroma' and use != 'Boil':
|
||||
continue
|
||||
|
||||
alerts.append(float(e.find('TIME').text))
|
||||
|
||||
## There might also be miscelaneous additions during boild time
|
||||
for e in recipe.findall('MISCS/MISC[USE="Boil"]'):
|
||||
alerts.append(float(e.find('TIME').text))
|
||||
|
||||
## Dedupe and order the additions by their time, to prevent multiple alerts at the same time
|
||||
alerts = sorted(list(set(alerts)))
|
||||
|
||||
## CBP should have these additions in reverse
|
||||
alerts.reverse()
|
||||
|
||||
return alerts
|
||||
|
||||
def getSteps(self, id):
|
||||
|
||||
|
||||
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
steps = []
|
||||
for e in e.findall('./RECIPE[%s]/MASH/MASH_STEPS/MASH_STEP' % (str(id))):
|
||||
|
||||
if self.api.get_config_parameter("unit", "C") == "C":
|
||||
temp = float(e.find("STEP_TEMP").text)
|
||||
else:
|
||||
temp = round(9.0 / 5.0 * float(e.find("STEP_TEMP").text) + 32, 2)
|
||||
|
||||
steps.append({"name": e.find("NAME").text, "temp": temp, "timer": float(e.find("STEP_TIME").text)})
|
||||
|
||||
return steps
|
||||
|
||||
@@ -29,7 +29,7 @@ class KBH(FlaskView):
|
||||
result.append({"id": row[0], "name": row[1], "brewed": row[2]})
|
||||
return json.dumps(result)
|
||||
except Exception as e:
|
||||
print e
|
||||
print(e)
|
||||
self.api.notify(headline="Failed to load KHB database", message="ERROR", type="danger")
|
||||
return ('', 500)
|
||||
finally:
|
||||
|
||||
@@ -43,6 +43,6 @@ def read_passive_sensor(api):
|
||||
:return: None
|
||||
|
||||
"""
|
||||
for key, value in cbpi.cache.get("sensors").iteritems():
|
||||
for key, value in cbpi.cache.get("sensors").items():
|
||||
if value.mode == "P":
|
||||
value.instance.read()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import endpoints
|
||||
@@ -109,7 +109,7 @@ class SystemView(FlaskView):
|
||||
vf = self.api.app.view_functions
|
||||
|
||||
for f in self.api.app.view_functions:
|
||||
print f
|
||||
print(f)
|
||||
endpoints = {}
|
||||
re = {
|
||||
"swagger": "2.0",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import endpoints
|
||||
File diff suppressed because one or more lines are too long
+14
-14
@@ -1,14 +1,14 @@
|
||||
Flask==0.11.1
|
||||
Flask-SocketIO==2.6.2
|
||||
eventlet==0.19.0
|
||||
greenlet==0.4.10
|
||||
python-dateutil==2.5.3
|
||||
python-engineio==0.9.2
|
||||
python-mimeparse==1.5.2
|
||||
python-socketio==1.4.4
|
||||
PyYAML==3.11
|
||||
requests==2.11.0
|
||||
Werkzeug==0.11.10
|
||||
httplib2==0.9.2
|
||||
flask-classy==0.6.10
|
||||
GitPython==2.1.3
|
||||
eventlet==0.25.0
|
||||
Flask==1.1.1
|
||||
Flask-Classy==0.6.10
|
||||
Flask-SocketIO==4.2.1
|
||||
GitPython==3.0.1
|
||||
greenlet==0.4.15
|
||||
httplib2==0.13.1
|
||||
python-dateutil==2.8.0
|
||||
python-engineio==3.9.3
|
||||
python-mimeparse==1.6.0
|
||||
python-socketio==4.3.1
|
||||
PyYAML==5.1.2
|
||||
requests==2.22.0
|
||||
Werkzeug==0.15.5
|
||||
Reference in New Issue
Block a user