cocothenut GitHub 8 år sedan
förälder
incheckning
af3e1c5aed
3 ändrade filer med 925 tillägg och 765 borttagningar
  1. +229
    -221
      modules/base_plugins/brew_steps/__init__.py
  2. +175
    -50
      modules/buzzer/__init__.py
  3. +521
    -494
      modules/core/core.py

+ 229
- 221
modules/base_plugins/brew_steps/__init__.py Visa fil

@@ -1,221 +1,229 @@
# -*- coding: utf-8 -*-
import time


from modules.core.props import Property, StepProperty
from modules.core.step import StepBase
from modules import cbpi



@cbpi.step
class MashStep(StepBase):
'''
Just put the decorator @cbpi.step on top of a method
'''
# Properties
temp = Property.Number("Temperature", configurable=True, description="Target Temperature of Mash Step")
kettle = StepProperty.Kettle("Kettle", description="Kettle in which the mashing takes place")
timer = Property.Number("Timer in Minutes", configurable=True, description="Timer is started when the target temperature is reached")

def init(self):
'''
Initialize Step. This method is called once at the beginning of the step
:return:
'''
# set target tep
self.set_target_temp(self.temp, self.kettle)

@cbpi.action("Start Timer Now")
def start(self):
'''
Custom Action which can be execute form the brewing dashboard.
All method with decorator @cbpi.action("YOUR CUSTOM NAME") will be available in the user interface
:return:
'''
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

def reset(self):
self.stop_timer()
self.set_target_temp(self.temp, self.kettle)

def finish(self):
self.set_target_temp(0, self.kettle)

def execute(self):
'''
This method is execute in an interval
:return:
'''

# Check if Target Temp is reached
if self.get_kettle_temp(self.kettle) >= float(self.temp):
# Check if Timer is Running
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

# Check if timer finished and go to next step
if self.is_timer_finished() == True:
self.next()


@cbpi.step
class MashInStep(StepBase):
'''
Just put the decorator @cbpi.step on top of a method
'''
# Properties
temp = Property.Number("Temperature", configurable=True, description="Target Temperature of Mash Step")
kettle = StepProperty.Kettle("Kettle", description="Kettle in which the mashing takes place")
s = False

@cbpi.action("Change Power")
def change_power(self):
self.actor_power(1, 50)

def init(self):
'''
Initialize Step. This method is called once at the beginning of the step
:return:
'''
# set target tep
self.s = False
self.set_target_temp(self.temp, self.kettle)



def execute(self):
'''
This method is execute in an interval
:return:
'''

# Check if Target Temp is reached
if self.get_kettle_temp(self.kettle) >= float(self.temp) and self.s is False:
self.s = True
self.notify("Step Temp Reached!", "Please press the next button to continue", timeout=None)



@cbpi.step
class ChilStep(StepBase):

timer = Property.Number("Timer in Minutes", configurable=True, default_value=0, description="Timer is started immediately")

@cbpi.action("Stat Timer")
def start(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

def reset(self):
self.stop_timer()


def finish(self):
pass

def execute(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

if self.is_timer_finished() == True:
self.next()

@cbpi.step
class PumpStep(StepBase):

pump = StepProperty.Actor("Pump", description="Pump actor gets toogled")
timer = Property.Number("Timer in Minutes", configurable=True, default_value=0, description="Timer is started immediately")

@cbpi.action("Stat Timer")
def start(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

def reset(self):
self.stop_timer()


def finish(self):
self.actor_off(int(self.pump))

def init(self):
self.actor_on(int(self.pump))

def execute(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

if self.is_timer_finished() == True:
self.next()

@cbpi.step
class BoilStep(StepBase):
'''
Just put the decorator @cbpi.step on top of a method
'''
# Properties
temp = Property.Number("Temperature", configurable=True, default_value=100, description="Target temperature for boiling")
kettle = StepProperty.Kettle("Kettle", description="Kettle in which the boiling step takes place")
timer = Property.Number("Timer in Minutes", configurable=True, default_value=90, description="Timer is started when target temperature is reached")
hop_1 = Property.Number("Hop 1 Addition", configurable=True, description="Fist Hop alert")
hop_1_added = Property.Number("",default_value=None)
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")

def init(self):
'''
Initialize Step. This method is called once at the beginning of the step
:return:
'''
# set target tep
self.set_target_temp(self.temp, self.kettle)




@cbpi.action("Start Timer Now")
def start(self):
'''
Custom Action which can be execute form the brewing dashboard.
All method with decorator @cbpi.action("YOUR CUSTOM NAME") will be available in the user interface
:return:
'''
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)

def reset(self):
self.stop_timer()
self.set_target_temp(self.temp, self.kettle)

def finish(self):
self.set_target_temp(0, self.kettle)


def check_hop_timer(self, number, value):

if self.__getattribute__("hop_%s_added" % number) is not True and time.time() > (
self.timer_end - (int(self.timer) * 60 - int(value) * 60)):
self.__setattr__("hop_%s_added" % number, True)
self.notify("Hop Alert", "Please add Hop %s" % number, timeout=None)

def execute(self):
'''
This method is execute in an interval
:return:
'''
# Check if Target Temp is reached
if self.get_kettle_temp(self.kettle) >= float(self.temp):
# Check if Timer is Running
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
else:
self.check_hop_timer(1, self.hop_1)
self.check_hop_timer(2, self.hop_2)
self.check_hop_timer(3, self.hop_3)
# Check if timer finished and go to next step
if self.is_timer_finished() == True:
self.next()
# -*- coding: utf-8 -*-
import time
from modules.core.props import Property, StepProperty
from modules.core.step import StepBase
from modules import cbpi
@cbpi.step
class MashStep(StepBase):
'''
Just put the decorator @cbpi.step on top of a method
'''
# Properties
temp = Property.Number("Temperature", configurable=True, description="Target Temperature of Mash Step")
kettle = StepProperty.Kettle("Kettle", description="Kettle in which the mashing takes place")
timer = Property.Number("Timer in Minutes", configurable=True, description="Timer is started when the target temperature is reached")
def init(self):
'''
Initialize Step. This method is called once at the beginning of the step
:return:
'''
# set target tep
self.set_target_temp(self.temp, self.kettle)
@cbpi.action("Start Timer Now")
def start(self):
'''
Custom Action which can be execute form the brewing dashboard.
All method with decorator @cbpi.action("YOUR CUSTOM NAME") will be available in the user interface
:return:
'''
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
def reset(self):
self.stop_timer()
self.set_target_temp(self.temp, self.kettle)
def finish(self):
self.set_target_temp(0, self.kettle)
def execute(self):
'''
This method is execute in an interval
:return:
'''
# Check if Target Temp is reached
if self.get_kettle_temp(self.kettle) >= float(self.temp):
# Check if Timer is Running
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
# Check if timer finished and go to next step
if self.is_timer_finished() == True:
# if you dont want a beep sound comment out like : # cbpi.MashStepEndBeep()
cbpi.MashStepEndBeep()
self.next()
@cbpi.step
class MashInStep(StepBase):
'''
Just put the decorator @cbpi.step on top of a method
'''
# Properties
temp = Property.Number("Temperature", configurable=True, description="Target Temperature of Mash Step")
kettle = StepProperty.Kettle("Kettle", description="Kettle in which the mashing takes place")
s = False
@cbpi.action("Change Power")
def change_power(self):
self.actor_power(1, 50)
def init(self):
'''
Initialize Step. This method is called once at the beginning of the step
:return:
'''
# set target tep
self.s = False
self.set_target_temp(self.temp, self.kettle)
def execute(self):
'''
This method is execute in an interval
:return:
'''
# Check if Target Temp is reached
if self.get_kettle_temp(self.kettle) >= float(self.temp) and self.s is False:
self.s = True
self.notify("Step Temp Reached!", "Please press the next button to continue", timeout=None)
# if you dont want a beep sound comment out like : # cbpi.MashInStepEndBeep()
cbpi.MashInStepEndBeep()
@cbpi.step
class ChilStep(StepBase):
timer = Property.Number("Timer in Minutes", configurable=True, default_value=0, description="Timer is started immediately")
@cbpi.action("Stat Timer")
def start(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
def reset(self):
self.stop_timer()
def finish(self):
pass
def execute(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
if self.is_timer_finished() == True:
# if you dont want a beep sound comment out like : # cbpi.ChilStepEndBeep()
cbpi.ChilStepEndBeep()
self.next()
@cbpi.step
class PumpStep(StepBase):
pump = StepProperty.Actor("Pump", description="Pump actor gets toogled")
timer = Property.Number("Timer in Minutes", configurable=True, default_value=0, description="Timer is started immediately")
@cbpi.action("Stat Timer")
def start(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
def reset(self):
self.stop_timer()
def finish(self):
self.actor_off(int(self.pump))
def init(self):
self.actor_on(int(self.pump))
def execute(self):
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
if self.is_timer_finished() == True:
# if you dont want a beep sound comment out like : # cbpi.PumpStepEndBeep()
cbpi.PumpStepEndBeep()
self.next()
@cbpi.step
class BoilStep(StepBase):
'''
Just put the decorator @cbpi.step on top of a method
'''
# Properties
temp = Property.Number("Temperature", configurable=True, default_value=100, description="Target temperature for boiling")
kettle = StepProperty.Kettle("Kettle", description="Kettle in which the boiling step takes place")
timer = Property.Number("Timer in Minutes", configurable=True, default_value=90, description="Timer is started when target temperature is reached")
hop_1 = Property.Number("Hop 1 Addition", configurable=True, description="Fist Hop alert")
hop_1_added = Property.Number("",default_value=None)
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")
def init(self):
'''
Initialize Step. This method is called once at the beginning of the step
:return:
'''
# set target tep
self.set_target_temp(self.temp, self.kettle)
@cbpi.action("Start Timer Now")
def start(self):
'''
Custom Action which can be execute form the brewing dashboard.
All method with decorator @cbpi.action("YOUR CUSTOM NAME") will be available in the user interface
:return:
'''
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
def reset(self):
self.stop_timer()
self.set_target_temp(self.temp, self.kettle)
def finish(self):
self.set_target_temp(0, self.kettle)
def check_hop_timer(self, number, value):
if self.__getattribute__("hop_%s_added" % number) is not True and time.time() > (
self.timer_end - (int(self.timer) * 60 - int(value) * 60)):
self.__setattr__("hop_%s_added" % number, True)
self.notify("Hop Alert", "Please add Hop %s" % number, timeout=None)
def execute(self):
'''
This method is execute in an interval
:return:
'''
# Check if Target Temp is reached
if self.get_kettle_temp(self.kettle) >= float(self.temp):
# Check if Timer is Running
if self.is_timer_finished() is None:
self.start_timer(int(self.timer) * 60)
else:
self.check_hop_timer(1, self.hop_1)
self.check_hop_timer(2, self.hop_2)
self.check_hop_timer(3, self.hop_3)
# Check if timer finished and go to next step
if self.is_timer_finished() == True:
# if you dont want a beep sound comment out like : # cbpi.BoilStepEndBeep()
cbpi.BoilStepEndBeep()
self.next()

+ 175
- 50
modules/buzzer/__init__.py Visa fil

@@ -1,50 +1,175 @@
import time
from thread import start_new_thread
from modules import cbpi

try:
import RPi.GPIO as GPIO
except Exception as e:
pass

class Buzzer(object):

sound = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
def __init__(self, gpio):
try:
cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
self.gpio = int(gpio)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio, GPIO.OUT)
self.state = True
cbpi.app.logger.info("BUZZER SETUP OK")
except Exception as e:
cbpi.app.logger.info("BUZZER EXCEPTION %s" % str(e))
self.state = False

def beep(self):
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return

def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass

start_new_thread(play, (self.sound,))

@cbpi.initalizer(order=1)
def init(cbpi):
gpio = cbpi.get_config_parameter("buzzer", 16)
cbpi.buzzer = Buzzer(gpio)
cbpi.beep()
cbpi.app.logger.info("INIT OK")
import time
from thread import start_new_thread
from modules import cbpi
try:
import RPi.GPIO as GPIO
except Exception as e:
pass
class Buzzer(object):
# custom beep sounds
sound = ["H", 0.1, "L"]
melodie1 = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
melodie2 = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
melodie3 = ["H", 0.4, "L", 0.1, "H", 0.4, "L", 0.1, "H", 0.4, "L"]
melodie4 = ["H", 0.4, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.4, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.4, "L"]
melodie5 = ["H", 0.6, "L", 0.3, "H", 0.6, "L", 0.3, "H", 0.6, "L"]
melodie6 = ["H", 0.2, "L", 0.4, "H", 0.2, "L", 0.3, "H", 0.2, "L", 0.2, "H", 0.2, "L", 0.1, "H", 0.2, "L", 0.1, "H", 0.2, "L"]
def __init__(self, gpio):
try:
cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
self.gpio = int(gpio)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.gpio, GPIO.OUT)
self.state = True
cbpi.app.logger.info("BUZZER SETUP OK")
except Exception as e:
cbpi.app.logger.info("BUZZER EXCEPTION %s" % str(e))
self.state = False
def beep(self): # beeps once when you boot up your Pi with CBPi -- beeps at Brewing finished
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.melodie2,))
def MashStepEndBeep(self): # beeps at end of step
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.melodie1,))
def MashInStepEndBeep(self): # beeps at end of step
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.melodie3,))
def ChilStepEndBeep(self): # beeps at end of step
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.melodie4,))
def PumpStepEndBeep(self): # beeps at end of step
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.melodie5,))
def BoilStepEndBeep(self): # beeps at end of step
if self.state is False:
cbpi.app.logger.error("BUZZER not working")
return
def play(sound):
try:
for i in sound:
if (isinstance(i, str)):
if i == "H":
GPIO.output(int(self.gpio), GPIO.HIGH)
else:
GPIO.output(int(self.gpio), GPIO.LOW)
else:
time.sleep(i)
except Exception as e:
pass
start_new_thread(play, (self.melodie6,))
@cbpi.initalizer(order=1)
def init(cbpi):
gpio = cbpi.get_config_parameter("buzzer", 16)
cbpi.buzzer = Buzzer(gpio)
cbpi.beep()
cbpi.MashStepEndBeep()
cbpi.MashInStepEndBeep()
cbpi.ChilStepEndBeep()
cbpi.PumpStepEndBeep()
cbpi.BoilStepEndBeep()
cbpi.app.logger.info("INIT OK")

+ 521
- 494
modules/core/core.py
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


Laddar…
Avbryt
Spara