- Refactoring

- Action Button with Parameter
- Actor Action with Parameter
- Sensor Action with Parameter
This commit is contained in:
Manuel83
2017-11-29 22:37:18 +01:00
parent 13836a5680
commit 9b7908c9c5
41 changed files with 8098 additions and 271 deletions
+31 -9
View File
@@ -1,15 +1,37 @@
from modules.core.baseapi import Buzzer
from modules.core.basetypes import Actor, KettleController, FermenterController
from modules.core.core import cbpi
from modules import cbpi
from modules.core.proptypes import Property
@cbpi.addon.actor.type("Dummy Actor")
class Dummy(Actor):
@cbpi.addon.actor.action("WOHOO")
def myaction(self):
print "WOOHOO"
pass
# Decorator to create a parameter based action
@cbpi.addon.actor.action("Run until Temp reached", parameters={"t": Property.Text(label="Target Temp")})
def check_sensor_value(self, t=1):
def check(api, id, value):
'''
Background Prozess which checks the sensor value every second
:param api:
:param id:
:param value:
:return:
'''
while api.sensor.get_value(1) < value:
api.sleep(1)
api.actor.off(id)
target_value = int(t)
# Create notificaiton
self.api.notify(headline="Waiting", message="Waiting for temp %s" % target_value)
# Switch actor on
self.api.actor.on(self.id, 100)
# Start Background task
self.api.start_background_task(check, self.api, id=self.id, value=target_value)
def on(self, power=100):
'''
@@ -17,11 +39,10 @@ class Dummy(Actor):
:param power: int value between 0 - 100
:return:
'''
print "ON"
print "ID %s ON" % self.id
def off(self):
print "OFF"
print "ID %s OFF" % self.id
@cbpi.addon.kettle.controller()
@@ -29,7 +50,7 @@ class MyController(KettleController):
def run(self):
while self.is_running():
print "HALLO"
self.sleep(1)
@@ -49,6 +70,7 @@ def init(cbpi):
class MyBuzzer(Buzzer):
def beep(self):
print "BEEEEEP"
pass
cbpi.buzzer = MyBuzzer()
+33 -13
View File
@@ -3,11 +3,12 @@ import os
from os.path import join
from modules.core.basetypes import Actor, Sensor
from modules.core.core import cbpi
from modules.core.basetypes import Actor, Sensor, Action
from modules import cbpi
from modules.core.proptypes import Property
import random
@cbpi.addon.sensor.type("Dummy Sensor")
class Dummy(Sensor):
@@ -21,10 +22,15 @@ class Dummy(Sensor):
else:
self.unit = "°F"
@cbpi.addon.sensor.action("WOHOO")
def myaction(self):
@cbpi.addon.sensor.action(label="Set Dummy Temp", parameters={
"p1":Property.Select(label="Temp",options=[1,2,3]),
})
def myaction(self, p1):
self.text = p1
self.update_value(int(p1))
self.api.notify(headline="WOHOO", message="HALLO")
def execute(self):
while True:
@@ -34,14 +40,28 @@ class Dummy(Sensor):
pass
self.api.sleep(5)
@cbpi.addon.core.action(key="clear", label="Clear all Logs")
def woohoo(cbpi):
dir = "./logs"
test = os.listdir(dir)
@cbpi.addon.core.action(name="Delete All Logs")
class ParameterAction(Action):
for item in test:
p1 = Property.Number("P1", configurable=True, description="Target Temperature of Mash Step", unit="C")
p2 = Property.Number("P2", configurable=True, description="Target Temperature of Mash Step", unit="C")
if item.endswith(".log"):
os.remove(join(dir, item))
cbpi.notify(headline="Logs Deleted",message="All Logs Cleared")
def execute(self, p1, p2, **kwargs):
for i in range(5):
cbpi.sleep(1)
cbpi.notify(headline="Woohoo", message="%s %s" % (p1, p2))
@cbpi.addon.core.action(name="Delete All Logs")
class DeleteAllLogs(Action):
def execute(self, **kwargs):
dir = "./logs"
test = os.listdir(dir)
for item in test:
if item.endswith(".log"):
os.remove(join(dir, item))
cbpi.notify(headline="Logs Deleted", message="All Logs Cleared")
+7 -4
View File
@@ -1,5 +1,5 @@
from modules.core.basetypes import Step
from modules.core.core import cbpi
from modules import cbpi
from modules.core.proptypes import Property
import time
@@ -18,7 +18,7 @@ class Dummy(Step):
time = Property.Text(label="Text", configurable=True, description="WOHOOO")
def execute(self):
#print self.text
pass
def reset(self):
@@ -36,8 +36,8 @@ class MashStep(Step):
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 = Property.Kettle("Kettle", description="Kettle in which the mashing takes place")
temp = Property.Number("Temperature", configurable=True, description="Target Temperature of Mash Step", unit="C")
kettle = Property.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):
@@ -79,6 +79,7 @@ class MashStep(Step):
# Check if timer finished and go to next step
if self.is_timer_finished() == True:
self.api.beep()
self.notify("Mash Step Completed!", "Starting the next step", timeout=None)
self.next()
@@ -243,3 +244,5 @@ class BoilStep(Step):
if self.is_timer_finished() == True:
self.notify("Boil Step Completed!", "Starting the next step", timeout=None)
self.next()