def load_configs(self): try: with open(os.path.expanduser("~/.tikibot.yaml"), "r") as f: confs = yaml.safe_load(f) except FileNotFoundError: confs = yaml.load(self.get_resource("tikibot_configs.yaml")) self.passcode = confs.get('passcode', '8888') self.use_metric = confs.get('use_metric', False) SupplyFeed.fromDict(confs) Recipe.fromDict(confs)
def _item_add_finish(self, name): remaining = 750 overage = 0.25 for lastfeed in SupplyFeed.getAllOrdered(): remaining = lastfeed.remaining overage = lastfeed.pulse_overage feed = SupplyFeed("Misc", name, remaining=remaining, overage=overage) self.master.save_configs() self.update_listbox() self.master.screen_pop() self.master.screen_push(FeedEditScreen(self.master, feed))
def _item_add_finish(self, name): flowrate = 14.2 overage = 0.25 for lastfeed in SupplyFeed.getAllOrdered(): flowrate = lastfeed.flowrate overage = lastfeed.pulse_overage feed = SupplyFeed("Misc", name, flowrate=flowrate, overage=overage) self.master.save_configs() self.update_listbox() self.master.screen_pop() self.master.screen_push(FeedEditScreen(self.master, feed))
def item_add(self): try: for n in range(99): name = "Feed %d" % (n + 1) SupplyFeed.getByName(name) except KeyError: pass self.master.screen_push( AlphaScreen(self.master, label="Name für neue Zutat:", defval=name, callback=self._item_add_finish))
def load_configs(self): try: with open(os.path.expanduser("~/.tikibot.yaml"), "r") as f: confs = yaml.load(f) except FileNotFoundError: confs = yaml.load(self.get_resource("tikibot_configs.yaml")) self.passcode = confs.get('passcode', '8888') self.use_metric = confs.get('use_metric', True) self.stepsforml = confs.get('stepsforml', "113") self.serdevice = confs.get('serdevice', '/dev/ttyUSB0') self.bgcolor = confs.get('bgcolor', '#94F92F') SupplyFeed.fromDict(confs) Recipe.fromDict(confs)
def add_ingredient(self, feedname, ml): feed = SupplyFeed.getByName(feedname) if feed not in Recipe.by_feed: Recipe.by_feed[feed] = [] Recipe.by_feed[feed].append(self) self.ingredients.append(Ingredient(feed, ml)) return self
def __init__(self, master): self.master = master feednames = [x.getName() for x in SupplyFeed.getAll()] cols = max(2, math.ceil(len(feednames) / 7)) super(ByIngredientScreen, self).__init__(master, feednames, labeltext="Find drinks by ingredient:", cols=cols)
def __init__(self, master): super(DumpScreen, self).__init__(master) self.master = master self.lbl = Label(self, text="Dumping all feeds") self.backbtn = RectButton(self, text="Stop", command=self.handle_button_back) self.lbl.pack(side=TOP, fill=BOTH, expand=1) self.backbtn.pack(side=BOTTOM, fill=X, padx=10, pady=10) for feed in SupplyFeed.getAll(): feed.startFeed()
def handle_button_ingr_add(self): currfeeds = [ingr.feed.name for ingr in self.recipe.ingredients] feeds = [ feed for feed in SupplyFeed.getNames() if feed not in currfeeds ] self.master.screen_push( SelectScreen(self.master, feeds, labeltext="Select the ingredient:", callback=self.add_ingredient_step1))
def save_configs(self): confs = { "conf_version": "1.0.0", "passcode": self.passcode, "use_metric": self.use_metric, } confs = SupplyFeed.toDictAll(confs) confs = Recipe.toDictAll(confs, metric=self.use_metric) with open(os.path.expanduser("~/.tikibot.yaml"), "w") as f: f.write(yaml.dump(confs))
def fromArray(cls, data): if type(data) is dict: name = data['name'] ml = data['ml'] else: name, amount, unit = data mult = unit_measures.get(unit, 0.0) ml = amount * mult feed = SupplyFeed.getByName(name) return cls(feed, ml)
def __init__(self, master): self.master = master feednames = [x.getName() for x in SupplyFeed.getAvailable()] cols = max(2, math.ceil(len(feednames) / 7)) super(ByIngredientScreen, self).__init__(master, feednames, labeltext="Suche Drinks nach Zutaten:", cols=cols) self.bgcolor = master.bgcolor self.configure(bg=self.bgcolor)
def save_configs(self): confs = { "conf_version": "1.0.0", "passcode": self.passcode, "use_metric": self.use_metric, "stepsforml": self.stepsforml, "serdevice": self.serdevice, "bgcolor": self.bgcolor, } confs = SupplyFeed.toDictAll(confs) confs = Recipe.toDictAll(confs, metric=self.use_metric) with open(os.path.expanduser("~/.tikibot.yaml"), "w") as f: yaml.dump(confs, f)
def startDispensing(self, volume): stepsforml = self.stepsforml tot_vol = self.totalVolume() vol_mult = volume / tot_vol self.dispensing = [] sercommand = '' self.dispenselist = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] logging.info("Dispensing: %s, %d ml" % (self.getName(), volume)) for ingr in self.ingredients: ingr.milliliters = math.ceil(ingr.milliliters * vol_mult) self.dispensing.append(DispensingIngredient(ingr, vol_mult)) for ingr in self.dispensing: thisfeed = SupplyFeed.getByName(ingr.feed.name) newremaining = thisfeed.feeds[ ingr.feed.name].remaining - ingr.milliliters thisfeed.feeds[ingr.feed.name].remaining = newremaining logging.debug("remaining neu fuer " + ingr.feed.name + ": " + str(thisfeed.feeds[ingr.feed.name].remaining)) logging.info("Zutat " + ingr.feed.name + ": " + str(ingr.milliliters) + " ml") for pumpnumber in list(range(24)): if ingr.feed.motor_num == pumpnumber: self.dispenselist[pumpnumber] = int( math.ceil(ingr.milliliters * self.stepsforml)) sercommand = (','.join(map(str, self.dispenselist))) + '\n' try: self.ser.readData() except: logging.debug("keine bestehende verbindung") try: self.ser = SerialConnection() self.ser.readData() logging.debug("habe verbindung") except: logging.debug("verbindung nicht moeglich") hwa = HardwareAction(self.mixit) hwa.do_dispensing(self.mixit) self.ser.sendData(sercommand) self.ser.close() del self.ser self.updateDispensing(self.mixit)
def item_lower(self, idx, txt, feed): SupplyFeed.transpose(idx) self.master.save_configs()
def handle_button_back(self): for feed in SupplyFeed.getAll(): feed.stopFeed() self.master.screen_pop()
def handle_button_select(self, item): feed = SupplyFeed.getByName(item) recipes = Recipe.getRecipesByFeed(feed) self.master.screen_push( RecipeScreen(self.master, recipes, "Wähle einen Drink mit %s:" % item))
def _get_items(self): return [{ "name": "#%d %s" % (feed.motor_num, feed.getName()), "data": feed, "fgcolor": None if feed.avail else "#700", } for feed in SupplyFeed.getAllOrdered()]
def handle_button_select(self, item): feed = SupplyFeed.getByName(item) recipes = Recipe.getRecipesByFeed(feed) self.master.screen_push( RecipeScreen(self.master, recipes, "Select a drink with %s:" % item))
def item_raise(self, idx, txt, feed): SupplyFeed.transpose(idx - 1) self.master.save_configs()