예제 #1
0
def api_pouring():
    if request.method == "POST":
        seconds = float(request.data.get("seconds"))
        HISTORY.saveEventManualPour(seconds)
        PUMP.setup()
        PUMP.start(seconds)
    return {"data": {}}
예제 #2
0
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": {}}
예제 #3
0
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
        }
    }
예제 #4
0
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]")
예제 #5
0
#SUBMODULE:HISTORY RESET

import HISTORY

HISTORY.reset()
예제 #6
0
#SUBMODULE:HISTORY TEST

import HISTORY

HISTORY.test()
예제 #7
0
def deviceInit():
    print("API - DEVICE INIT")
    if request.method == "GET":
        time = HISTORY.save_deviceInit()

    return {"data": {"time": time}}
예제 #8
0
def api_history():
    if request.method == "GET":
        events = HISTORY.loadAllEvents()
    return {"data": {"events": events}}
예제 #9
0
def api_init():
    if request.method == "POST":
        HISTORY.saveEventDeviceInit()
    return {"data": {}}