mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
fix issues #55
This commit is contained in:
parent
de38fbc80c
commit
d8b083003d
2 changed files with 53 additions and 57 deletions
|
@ -1,23 +1,20 @@
|
|||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from enum import Enum
|
||||
from abc import abstractmethod
|
||||
|
||||
from cbpi.api.base import CBPiBase
|
||||
from cbpi.api.config import ConfigType
|
||||
|
||||
__all__ = ["StepResult", "StepState", "StepMove", "CBPiStep"]
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class StepResult(Enum):
|
||||
STOP = 1
|
||||
NEXT = 2
|
||||
DONE = 3
|
||||
ERROR = 4
|
||||
|
||||
|
||||
class StepState(Enum):
|
||||
INITIAL = "I"
|
||||
DONE = "D"
|
||||
|
@ -25,10 +22,12 @@ class StepState(Enum):
|
|||
ERROR = "E"
|
||||
STOP = "S"
|
||||
|
||||
|
||||
class StepMove(Enum):
|
||||
UP = -1
|
||||
DOWN = 1
|
||||
|
||||
|
||||
class CBPiStep(CBPiBase):
|
||||
|
||||
def __init__(self, cbpi, id, name, props, on_done) -> None:
|
||||
|
@ -40,21 +39,25 @@ class CBPiStep(CBPiBase):
|
|||
self.props = props
|
||||
self.cancel_reason: StepResult = None
|
||||
self.summary = ""
|
||||
self.running: bool = False
|
||||
|
||||
def _done(self, task):
|
||||
self._done_callback(self, task.result())
|
||||
|
||||
async def start(self):
|
||||
self.running = True
|
||||
self.task = asyncio.create_task(self._run())
|
||||
self.task.add_done_callback(self._done)
|
||||
|
||||
async def next(self):
|
||||
self.running = False
|
||||
self.cancel_reason = StepResult.NEXT
|
||||
self.task.cancel()
|
||||
await self.task
|
||||
|
||||
async def stop(self):
|
||||
try:
|
||||
self.running = False
|
||||
self.cancel_reason = StepResult.STOP
|
||||
self.task.cancel()
|
||||
await self.task
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
import asyncio
|
||||
from cbpi.api.step import CBPiStep, StepResult
|
||||
from cbpi.api.timer import Timer
|
||||
|
||||
from cbpi.api import *
|
||||
import logging
|
||||
from cbpi.api.step import StepResult
|
||||
from cbpi.api.timer import Timer
|
||||
|
||||
|
||||
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True),
|
||||
|
@ -46,7 +45,6 @@ class MashStep(CBPiStep):
|
|||
return StepResult.DONE
|
||||
|
||||
|
||||
|
||||
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True)])
|
||||
class WaitStep(CBPiStep):
|
||||
|
||||
|
@ -54,12 +52,10 @@ class WaitStep(CBPiStep):
|
|||
async def hello(self, **kwargs):
|
||||
print("ACTION")
|
||||
|
||||
|
||||
@action(key="Custom Step Action 2", parameters=[])
|
||||
async def hello2(self, **kwargs):
|
||||
print("ACTION2")
|
||||
|
||||
|
||||
async def on_timer_done(self, timer):
|
||||
self.summary = ""
|
||||
await self.next()
|
||||
|
@ -86,6 +82,7 @@ class WaitStep(CBPiStep):
|
|||
await asyncio.sleep(1)
|
||||
return StepResult.DONE
|
||||
|
||||
|
||||
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True),
|
||||
Property.Actor(label="Actor")])
|
||||
class ActorStep(CBPiStep):
|
||||
|
@ -162,6 +159,7 @@ class BoilStep(CBPiStep):
|
|||
self.timer.is_running = True
|
||||
return StepResult.DONE
|
||||
|
||||
|
||||
def setup(cbpi):
|
||||
'''
|
||||
This method is called by the server during startup
|
||||
|
@ -175,8 +173,3 @@ def setup(cbpi):
|
|||
cbpi.plugin.register("WaitStep", WaitStep)
|
||||
cbpi.plugin.register("MashStep", MashStep)
|
||||
cbpi.plugin.register("ActorStep", ActorStep)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue