2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-07 13:08:13 +01:00
|
|
|
import asyncio
|
2021-02-16 20:37:51 +01:00
|
|
|
from cbpi.api.step import CBPiStep, StepResult
|
2021-02-10 07:38:55 +01:00
|
|
|
from cbpi.api.timer import Timer
|
2021-02-07 13:08:13 +01:00
|
|
|
from cbpi.api import *
|
2021-02-10 07:38:55 +01:00
|
|
|
import logging
|
2021-02-07 13:08:13 +01:00
|
|
|
|
2021-02-10 07:38:55 +01:00
|
|
|
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True),
|
2021-02-07 13:08:13 +01:00
|
|
|
Property.Number(label="Temp", configurable=True),
|
2021-02-10 07:38:55 +01:00
|
|
|
Property.Sensor(label="Sensor"),
|
2021-02-07 13:08:13 +01:00
|
|
|
Property.Kettle(label="Kettle")])
|
|
|
|
class MashStep(CBPiStep):
|
|
|
|
|
2021-02-27 20:09:19 +01:00
|
|
|
@action(key="Custom RESET", parameters=[])
|
|
|
|
async def custom_reset(self, **kwargs):
|
|
|
|
self.summary = ""
|
|
|
|
await self.push_update()
|
2021-02-20 12:59:23 +01:00
|
|
|
|
2021-02-27 20:09:19 +01:00
|
|
|
|
|
|
|
@action(key="Custom Action", parameters=[Property.Number(label="Value", configurable=True)])
|
|
|
|
async def custom_action(self, Value, **kwargs):
|
|
|
|
self.summary = "VALUE FROM ACTION {}".format(Value)
|
|
|
|
await self.push_update()
|
|
|
|
self.cbpi.notify("ACTION 2 CALLED".format(Value))
|
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_timer_done(self,timer):
|
|
|
|
self.summary = ""
|
|
|
|
await self.next()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_timer_update(self,timer, seconds):
|
|
|
|
self.summary = Timer.format_time(seconds)
|
|
|
|
await self.push_update()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_start(self):
|
2021-02-10 07:38:55 +01:00
|
|
|
if self.timer is None:
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-16 20:37:51 +01:00
|
|
|
self.summary = "Waiting for Target Temp"
|
|
|
|
await self.push_update()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_stop(self):
|
|
|
|
await self.timer.stop()
|
|
|
|
self.summary = ""
|
|
|
|
await self.push_update()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
|
|
|
async def reset(self):
|
2021-02-27 20:09:19 +01:00
|
|
|
self.summary = ""
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-07 13:08:13 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def run(self):
|
2021-02-10 07:38:55 +01:00
|
|
|
while True:
|
|
|
|
await asyncio.sleep(1)
|
2021-02-16 20:37:51 +01:00
|
|
|
sensor_value = self.get_sensor_value(self.props.Sensor)
|
|
|
|
if sensor_value.get("value") >= int(self.props.Temp) and self.timer == None:
|
2021-02-17 23:52:54 +01:00
|
|
|
self.timer.start()
|
2021-02-16 20:37:51 +01:00
|
|
|
return StepResult.DONE
|
|
|
|
|
2021-02-10 07:38:55 +01:00
|
|
|
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True)])
|
|
|
|
class WaitStep(CBPiStep):
|
|
|
|
|
2021-02-20 12:59:23 +01:00
|
|
|
@action(key="Custom Step Action", parameters=[])
|
|
|
|
async def hello(self, **kwargs):
|
|
|
|
print("ACTION")
|
2021-02-27 20:09:19 +01:00
|
|
|
self.cbpi.notify("ACTION 1 CALLED")
|
2021-02-20 12:59:23 +01:00
|
|
|
|
|
|
|
@action(key="Custom Step Action 2", parameters=[])
|
|
|
|
async def hello2(self, **kwargs):
|
|
|
|
print("ACTION2")
|
2021-02-27 20:09:19 +01:00
|
|
|
self.cbpi.notify("ACTION 2 CALLED")
|
2021-02-20 12:59:23 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_timer_done(self,timer):
|
|
|
|
self.summary = ""
|
|
|
|
await self.next()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_timer_update(self,timer, seconds):
|
|
|
|
self.summary = Timer.format_time(seconds)
|
|
|
|
await self.push_update()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_start(self):
|
2021-02-10 07:38:55 +01:00
|
|
|
if self.timer is None:
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) * 60,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-10 07:38:55 +01:00
|
|
|
self.timer.start()
|
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_stop(self):
|
|
|
|
await self.timer.stop()
|
|
|
|
self.summary = ""
|
|
|
|
await self.push_update()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
|
|
|
async def reset(self):
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) * 60,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def run(self):
|
2021-02-10 07:38:55 +01:00
|
|
|
while True:
|
|
|
|
await asyncio.sleep(1)
|
2021-02-16 20:37:51 +01:00
|
|
|
return StepResult.DONE
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-12 00:03:18 +01:00
|
|
|
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True),
|
2021-02-10 07:38:55 +01:00
|
|
|
Property.Actor(label="Actor")])
|
|
|
|
class ActorStep(CBPiStep):
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_timer_done(self,timer):
|
|
|
|
self.summary = ""
|
|
|
|
await self.next()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_timer_update(self,timer, seconds):
|
|
|
|
self.summary = Timer.format_time(seconds)
|
|
|
|
await self.push_update()
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_start(self):
|
2021-02-10 07:38:55 +01:00
|
|
|
if self.timer is None:
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) * 60,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-10 07:38:55 +01:00
|
|
|
self.timer.start()
|
2021-02-16 20:37:51 +01:00
|
|
|
await self.actor_on(self.props.Actor)
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def on_stop(self):
|
|
|
|
await self.actor_off(self.props.Actor)
|
|
|
|
await self.timer.stop()
|
|
|
|
self.summary = ""
|
|
|
|
await self.push_update()
|
|
|
|
|
|
|
|
async def reset(self):
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-16 20:37:51 +01:00
|
|
|
async def run(self):
|
2021-02-10 07:38:55 +01:00
|
|
|
|
|
|
|
while True:
|
|
|
|
await asyncio.sleep(1)
|
2021-02-16 20:37:51 +01:00
|
|
|
return StepResult.DONE
|
|
|
|
|
2021-02-17 23:52:54 +01:00
|
|
|
|
|
|
|
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True),
|
|
|
|
Property.Number(label="Temp", description="Boil temperature", configurable=True),
|
|
|
|
Property.Sensor(label="Sensor"),
|
|
|
|
Property.Kettle(label="Kettle")])
|
|
|
|
class BoilStep(CBPiStep):
|
|
|
|
|
|
|
|
async def on_timer_done(self,timer):
|
|
|
|
self.summary = ""
|
|
|
|
await self.next()
|
|
|
|
|
|
|
|
async def on_timer_update(self,timer, seconds):
|
|
|
|
self.summary = Timer.format_time(seconds)
|
|
|
|
await self.push_update()
|
|
|
|
|
|
|
|
async def on_start(self):
|
|
|
|
if self.timer is None:
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-17 23:52:54 +01:00
|
|
|
|
|
|
|
self.summary = "Waiting for Target Temp"
|
|
|
|
await self.push_update()
|
|
|
|
|
|
|
|
async def on_stop(self):
|
|
|
|
await self.timer.stop()
|
|
|
|
self.summary = ""
|
|
|
|
await self.push_update()
|
|
|
|
|
|
|
|
async def reset(self):
|
2021-02-19 22:24:15 +01:00
|
|
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
2021-02-17 23:52:54 +01:00
|
|
|
|
|
|
|
@action("Start Timer", [])
|
|
|
|
async def star_timer(self):
|
|
|
|
self.cbpi.notify("Timer started")
|
|
|
|
self.timer.start()
|
|
|
|
|
|
|
|
async def run(self):
|
|
|
|
while True:
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
sensor_value = self.get_sensor_value(self.props.Sensor)
|
|
|
|
if sensor_value is not None and sensor_value.get("value") >= int(self.props.Temp) and self.timer == None:
|
|
|
|
self.timer.start()
|
|
|
|
return StepResult.DONE
|
|
|
|
|
2021-02-07 13:08:13 +01:00
|
|
|
def setup(cbpi):
|
|
|
|
'''
|
|
|
|
This method is called by the server during startup
|
|
|
|
Here you need to register your plugins at the server
|
|
|
|
|
|
|
|
:param cbpi: the cbpi core
|
|
|
|
:return:
|
2021-02-16 20:37:51 +01:00
|
|
|
'''
|
2021-02-10 07:38:55 +01:00
|
|
|
|
2021-02-17 23:52:54 +01:00
|
|
|
cbpi.plugin.register("BoilStep", BoilStep)
|
2021-02-10 07:38:55 +01:00
|
|
|
cbpi.plugin.register("WaitStep", WaitStep)
|
2021-02-07 13:08:13 +01:00
|
|
|
cbpi.plugin.register("MashStep", MashStep)
|
2021-02-16 20:37:51 +01:00
|
|
|
cbpi.plugin.register("ActorStep", ActorStep)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-07 13:08:13 +01:00
|
|
|
|