def api_pouring(): if request.method == "POST": seconds = float(request.data.get("seconds")) HISTORY.saveEventManualPour(seconds) PUMP.setup() PUMP.start(seconds) return {"data": {}}
def manualPouring(): print("API - POURING") if request.method == "POST": ml = int(request.data.get("ml")) HISTORY.save_manualPour(ml) duration = CONVERTOR.getDurationFrom(ml) PUMP.start(duration) return {"data": {}}
def getDevice(): print("API - DEVICE") if request.method == "GET": volumeMax = DATA.load_volumeMax() warningPercentage = DATA.load_warningPercentage() warningDaysLeft = DATA.load_warningDaysLeft() pouringInProgress = DATA.load_pouringInProgress() percentage = DATA.load_percentage() volume = DATA.load_volume() daysLeft = DATA.load_daysLeft() name = DATA.load_name() date = DATA.load_date() ml = DATA.load_ml() skipDays = DATA.load_skipDays() events = HISTORY.load_allEvents() return { "data": { "volumeMax": volumeMax, "warningPercentage": warningPercentage, "warningDaysLeft": warningDaysLeft, "pouringInProgress": pouringInProgress, "percentage": percentage, "volume": volume, "daysLeft": daysLeft, "name": name, "date": date, "ml": ml, "skipDays": skipDays, "events": events } }
def pourIfNeeded(): print("SCHEDULE - POUR IF NEEDED") isScheduleEnabled = DATA.load_enabled() if isScheduleEnabled == 1: next = TIMES.dateFrom(DATA.load_date()) print("SCHEDULE - POUR IF NEEDED - NEXT:") print(next) now = datetime.datetime.now() print("SCHEDULE - POUR IF NEEDED - NOW:") print(now) skipDays = DATA.load_skipDays() ml = DATA.load_ml() if now.date() == next.date() and now.time().hour == next.time().hour and now.time().minute == next.time().minute: print("SCHEDULE - POUR IF NEEDED - [IT IS TIME!]") volume = DATA.load_volume() if volume >= ml: #Pouring... HISTORY.save_automaticPour(ml) duration = CONVERTOR.getDurationFrom(ml) PUMP.start(duration) else: HISTORY.save_automaticPourNotPossible(ml) #NOT ENOUGH WATER #Prepare next. scheduled = next + datetime.timedelta(days=skipDays+1) DATA.save_date(TIMES.stringFrom(scheduled)) elif now > next: print("SCHEDULE - POUR IF NEEDED - [NEED TO UPDATE AUTOMATIC_POUR_SCHEDULED DATE]") while next <= now: HISTORY.save_automaticPourNotPossibleWithDate(ml,next) #DEVICE OFFLINE next = next + datetime.timedelta(days=skipDays+1) DATA.save_date(TIMES.stringFrom(next)) else: print("SCHEDULE - POUR IF NEEDED - [IT IS NOT TIME YET]")
#SUBMODULE:HISTORY RESET import HISTORY HISTORY.reset()
#SUBMODULE:HISTORY TEST import HISTORY HISTORY.test()
def deviceInit(): print("API - DEVICE INIT") if request.method == "GET": time = HISTORY.save_deviceInit() return {"data": {"time": time}}
def api_history(): if request.method == "GET": events = HISTORY.loadAllEvents() return {"data": {"events": events}}
def api_init(): if request.method == "POST": HISTORY.saveEventDeviceInit() return {"data": {}}