from __future__ import annotations from typing import Union from enum import Enum from ..draw_utils import draw_clock class Recipe: def __init__(self, name: str, steps: list[Step]): self.name = name self.steps = steps + [Step(StepType.SECTION, "Enjoy")] def __str__(self): return self.name class StepType(Enum): SECTION = 0 WEIGH = 1 START_TIME = 2 WAIT_TIME_FINISHED = 3 TARE = 4 def render(self, draw, position, fill='black') -> str: if self == StepType.SECTION: draw.text(position, "T", fill=fill) elif self == StepType.WEIGH: draw.text(position, "W", fill=fill) elif self == StepType.START_TIME or self == StepType.WAIT_TIME_FINISHED: draw_clock(draw, (position[0] + 3, position[1] + 5), radius=3, color=fill) elif self == StepType.TARE: draw.text(position, "0.0g", fill=fill) class Step: def __init__(self, step_type: StepType, value: float | str = None): self.step_type = step_type self.value = value @property def value_str(self) -> str: if self.step_type in [StepType.WEIGH]: return f"{self.value}g" elif self.step_type == StepType.START_TIME: if self.value == -1: return "Start" else: minutes = self.value // 60 seconds = self.value % 60 if minutes == 0: return f"{seconds}s" else: return f"{minutes}:{seconds:02d}" elif self.step_type == StepType.SECTION: return str(self.value) elif self.step_type == StepType.TARE: return "Tare" elif self.step_type == StepType.WAIT_TIME_FINISHED: return "Wait" else: return "" ###### example recipes ######### V60 = Recipe( "V60", [ Step(StepType.SECTION, "Grind"), Step(StepType.TARE), Step(StepType.WEIGH, 15), Step(StepType.SECTION, "Brew"), Step(StepType.TARE), Step(StepType.START_TIME, 45), Step(StepType.WEIGH, 50), Step(StepType.WAIT_TIME_FINISHED), Step(StepType.START_TIME, -1), Step(StepType.WEIGH, 250), ] ) ESPRESSO = Recipe( "Espresso", [ Step(StepType.SECTION, "Grind"), Step(StepType.TARE), Step(StepType.WEIGH, 18), Step(StepType.SECTION, "Brew"), Step(StepType.TARE), Step(StepType.START_TIME, -1), Step(StepType.WEIGH, 40), ] )