craftbeerpi4-pione/cbpi/extension/mashstep/__init__.py

184 lines
6 KiB
Python
Raw Normal View History

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-03-15 12:59:55 +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-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-03-15 12:59:55 +01:00
if self.cbpi.kettle is not None:
await self.cbpi.kettle.set_target_temp(self.props.Kettle, int(self.props.Temp))
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-03-14 11:52:46 +01:00
while True:
2021-02-10 07:38:55 +01:00
await asyncio.sleep(1)
2021-02-16 20:37:51 +01:00
sensor_value = self.get_sensor_value(self.props.Sensor)
2021-03-08 07:54:58 +01:00
if sensor_value.get("value") >= int(self.props.Temp) and self.timer.is_running is not True:
self.timer.start()
2021-03-08 07:54:58 +01:00
self.timer.is_running = True
2021-02-16 20:37:51 +01:00
return StepResult.DONE
2021-03-08 07:54:58 +01:00
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-03-08 07:54:58 +01:00
2021-02-20 12:59:23 +01:00
@action(key="Custom Step Action 2", parameters=[])
async def hello2(self, **kwargs):
print("ACTION2")
2021-03-08 07:54:58 +01:00
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-03-15 12:59:55 +01:00
if self.cbpi.kettle is not None:
await self.cbpi.kettle.set_target_temp(self.props.Kettle, int(self.props.Temp))
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):
while self.running == True:
2021-02-10 07:38:55 +01:00
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):
while self.running == True:
2021-02-10 07:38:55 +01:00
await asyncio.sleep(1)
2021-02-16 20:37:51 +01:00
return StepResult.DONE
@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)
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)
@action("Start Timer", [])
async def star_timer(self):
2021-03-08 07:54:58 +01:00
self.timer.start()
async def run(self):
while self.running == True:
await asyncio.sleep(1)
sensor_value = self.get_sensor_value(self.props.Sensor)
2021-03-08 07:54:58 +01:00
if sensor_value.get("value") >= int(self.props.Temp) and self.timer.is_running is not True:
self.timer.start()
2021-03-08 07:54:58 +01:00
self.timer.is_running = True
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
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