Skip to content

Commit

Permalink
add 2nd status text option for steps
Browse files Browse the repository at this point in the history
  • Loading branch information
avollkopf committed Dec 28, 2024
1 parent 4f2f3ba commit 839e6ca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.4.9"
__codename__ = "Yeast Starter"
__version__ = "4.5.0.a1"
__codename__ = "Cross Country"

3 changes: 2 additions & 1 deletion cbpi/api/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def __str__(self):
def to_dict(self):

msg = self.instance.summary if self.instance is not None else ""
return dict(id=self.id, name=self.name, state_text=msg, type=self.type, status=self.status.value, props=self.props.to_dict())
msg2 = self.instance.summary2 if ((self.instance is not None) and (self.instance.summary2 is not None)) else None
return dict(id=self.id, name=self.name, state_text=msg, state_text2=msg2, type=self.type, status=self.status.value, props=self.props.to_dict())

@dataclass
class Fermenter:
Expand Down
1 change: 1 addition & 0 deletions cbpi/api/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, cbpi, id, name, props, on_done) -> None:
self.props = props
self.cancel_reason: StepResult = None
self.summary = ""
self.summary2 = None
self.task = None
self.running: bool = False
self.logger = logging.getLogger(__name__)
Expand Down
26 changes: 24 additions & 2 deletions cbpi/extension/mashstep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ async def on_start(self):
#self.dwelltime=int(self.props.get("DwellTime", 0))*60
self.dwelltime=5*60 #tested with 5 minutes -> not exactly 5 min due to accuracy of asyncio.sleep
self.deviationlimit=0.3 # derived from a test
logging.warning(self.AutoTimer)
#logging.warning(self.AutoTimer)
self.summary2=None

self.kettle=self.get_kettle(self.props.get("Kettle", None))
if self.kettle is not None:
Expand All @@ -405,6 +406,24 @@ async def on_start(self):
await self.setAutoMode(True)
await self.push_update()

async def next_hop_timer(self):
hop_timers = []
for x in range(1, 6):
try:
hop = int(self.props.get("Hop_%s" % x, None)) * 60
except:
hop = None
if hop is not None:
hop_left = self.remaining_seconds - hop
if hop_left > 0:
hop_timers.append(hop_left)

if len(hop_timers) != 0:
next_hop_timer = time.strftime("%H:%M:%S", time.gmtime(min(hop_timers)))
else:
next_hop_timer = None
return next_hop_timer

async def check_hop_timer(self, number, value, text):
if value is not None and self.hops_added[number-1] is not True:
if self.remaining_seconds != None and self.remaining_seconds <= (int(value) * 60 + 1):
Expand All @@ -417,6 +436,7 @@ async def check_hop_timer(self, number, value, text):
async def on_stop(self):
await self.timer.stop()
self.summary = ""
self.summary2 = None
self.kettle.target_temp = 0
if self.AutoMode == True:
await self.setAutoMode(False)
Expand Down Expand Up @@ -456,7 +476,9 @@ async def run(self):
estimated_completion_time = datetime.fromtimestamp(time.time()+ (int(self.props.get("Timer", 0)))*60)
self.cbpi.notify(self.name, 'Timer started. Estimated completion: {}'.format(estimated_completion_time.strftime("%H:%M")), NotificationType.INFO)
else:
for x in range(1, 6):
nexthoptimer=await self.next_hop_timer()
self.summary2="Add Hop in: %s" % nexthoptimer if nexthoptimer is not None else None
for x in range(1, 6):
await self.check_hop_timer(x, self.props.get("Hop_%s" % x, None), self.props.get("Hop_%s_text" % x, None))

return StepResult.DONE
Expand Down
2 changes: 2 additions & 0 deletions cbpi/http_endpoints/http_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from cbpi.api.dataclasses import Props, Step
from aiohttp import web
from cbpi.api import *
import logging

class StepHttpEndpoints():

Expand All @@ -10,6 +11,7 @@ def __init__(self, cbpi):
self.controller : StepController = cbpi.step
self.cbpi.register(self, "/step2")

# Check if this is still needed
def create_dict(self, data):
return dict(name=data["name"], id=data["id"], type=data.get("type"), status=data["status"],props=data["props"], state_text=data["instance"].get_state())

Expand Down

0 comments on commit 839e6ca

Please sign in to comment.