예제 #1
0
def frontEndTemp():
    if request.method == "POST":
        data = request.get_json()
        info["temp"] = data
        getData.post_request(URL + "temp", {'data': data})
        return jsonify(error=False, msg="Success", code=200, data='')
    else:  #get
        return jsonify(error=False, msg="Success", code=200, data=info["temp"])
예제 #2
0
def manual(info):
    now = datetime.datetime.now()
    opentime = info["settings"]["open_time"]
    if now.hour == opentime[0] and now.minute == opentime[1]:
        getData.post_request(URL + "command", {"data": "open"})

    closetime = info["settings"]["close_time"]
    if now.hour == closetime[0] and now.minute == closetime[1]:
        getData.post_request(URL + "command", {"data": "close"})

    return info
예제 #3
0
def frontEndSettings():
    if request.method == "POST":
        data = request.get_json()
        info["settings"] = data
        getData.post_request(URL + "settings", {'data': json.dumps(data)})
        return jsonify(error=False, msg="Success", code=200, data='')
    else:  #get
        return jsonify(error=False,
                       msg="Success",
                       code=200,
                       data=info["settings"])
예제 #4
0
def sendWindowState():
    if request.method == "POST":
        data = request.get_json()
        info["command"] = data
        getData.post_request(URL + "command", {"data": info["command"]})
        return jsonify(error=False, msg="Success", code=200, data='')
    else:
        return jsonify(error=False,
                       msg="Success",
                       code=200,
                       data=info["windowState"])
예제 #5
0
def automatic(info):
    """
    the auto open and close function
    :param info: the infomation contain the temp humid and other stuff
    :return:
    """
    set_temp = float(info["settings"]["pref_temp"])
    set_humid = 45

    percipitation = info["precip"]

    tempDiff = abs(info["temp"]["outside"] - float(info["temp"]["inside"]))
    tempin = float(info["temp"]["inside"])
    tempout = info["temp"]["outside"]
    safetemphigh = set_temp + 6.0
    safetemplow = set_temp - 6.0

    humidin = float(info["humidity"]["inside"])
    humidout = info["humidity"]["outside"]
    safehumidhigh = set_humid + 2.0
    safehumidlow = set_humid - 2.0
    humidDiff = abs(info["humidity"]["outside"] -
                    float(info["humidity"]["inside"]))

    check = "temp"

    if percipitation == "True":  #if rain or not
        getData.post_request(URL + "command", {"data": "close"})
    elif tempin >= safetemplow and tempin <= safetemphigh:  # safe range of the set temp
        check = "hum"
    elif tempin < set_temp:  # compare the temp to know if open or not
        if tempout >= set_temp:
            getData.post_request(URL + "command", {"data": "open"})
        elif tempout < set_temp:
            if tempDiff > 5:
                getData.post_request(URL + "command", {"data": "open"})
            else:
                getData.post_request(URL + "command", {"data": "close"})
    elif tempin > set_temp:
        if tempout < set_temp:
            getData.post_request(URL + "command", {"data": "open"})
        elif tempout > set_temp:
            if tempDiff < 5:
                getData.post_request(URL + "command", {"data": "open"})
            else:
                getData.post_request(URL + "command", {"data": "close"})

    if check == "hum":
        if humidin >= safehumidlow and humidin <= safehumidhigh:  # safe humid range
            pass
        elif humidin < set_humid:  # compare the humid to determent if open or close
            if humidout >= set_humid:
                getData.post_request(URL + "command", {"data": "open"})
            elif humidout < set_humid:
                if humidDiff > 10:
                    getData.post_request(URL + "command", {"data": "open"})
                else:
                    getData.post_request(URL + "command", {"data": "close"})
        elif humidin >= set_humid:
            if humidout <= set_humid:
                getData.post_request(URL + "command", {"data": "open"})
            elif humidout > set_humid:
                if humidDiff < 10:
                    getData.post_request(URL + "command", {"data": "open"})
                else:
                    getData.post_request(URL + "command", {"data": "close"})
    return info
예제 #6
0
def sendCommand():
    if request.method == "POST":
        data = request.get_json()
        info["command"] = data['data']
        getData.post_request(URL + "command", {"data": info["command"]})
        return jsonify(error=False, msg="Success", code=200, data='')