Exemplo n.º 1
0
def index():

    conf = app_config.get()

    if conf["bridge_ip"] == "XXX.XXX.XXX.XXX":

        return render_template('index.html',
                               selections=app_config.get(),
                               dashboard_html=None,
                               nhl_html=None,
                               nfl_html=None,
                               config_html=Markup(render_template('packages/app_config.html',
                                                                  selections=app_config.get())))

    else:

        return render_template('index.html',
                               selections=app_config.get(),
                               dashboard_html=get_html(),
                               nhl_html=nhl.get_html(),
                               nfl_html=nfl.get_html(),
                               config_html=Markup(render_template('packages/app_config.html',
                                                                  selections=app_config.get())))
Exemplo n.º 2
0
def trigger(sport):

    original_state = get_state(sport)

    conf = app_config.get()

    url_end = "state" if conf[
        sport + "_alert_selection_type"] == "lights" else "action"

    url = "http://" + conf["bridge_ip"] + "/api/" + conf["user_token"] + "/" +\
          conf[sport + "_alert_selection_type"] + "/" + conf[sport + "_alert_selection_id"] + "/" + url_end

    try:

        json_data = json.loads(conf[sport + "_alert_style"])

    except TypeError:

        json_data = conf[sport + "_alert_style"]

    cycle = 0

    while cycle != conf[sport + "_alert_cycles"]:

        params = json.dumps(json_data).encode("utf-8")

        request = api.Request(url,
                              data=params,
                              headers=conf["headers"],
                              method="PUT")

        api.urlopen(request)

        sleep(1)

        cycle += 1

    # Returns to previous state
    params = json.dumps(original_state).encode("utf-8")

    request = api.Request(url,
                          data=params,
                          headers=conf["headers"],
                          method="PUT")

    api.urlopen(request)
Exemplo n.º 3
0
def get_teams():

    conf = app_config.get()

    response = api.urlopen(conf["nfl_url"] + "teams.json")

    team_json = json.loads(response.read().decode())

    teams_list = []

    for team in team_json["teams"]:

        json_team = {"abbr": str(team["abbr"]), "name": team["fullName"]}

        teams_list.append(json_team)

    return teams_list
Exemplo n.º 4
0
def get_info(selection):

    configuration = app_config.get()

    json_list = []

    url = "http://" + configuration["bridge_ip"] + "/api/" + configuration[
        "user_token"] + "/" + selection

    response_json = json.loads(api.urlopen(url).read().decode())

    for item in response_json:

        return_json = {"id": item, "name": response_json[item]["name"]}

        json_list.append(return_json)

    return json_list
Exemplo n.º 5
0
def set_bridge():

    bridge_ip = request.form["bridge_ip"]

    app_config.save("bridge_ip", bridge_ip)

    # FixMe - Determine Host Error and place here
    if app_config.get()["user_token"] != "PLACEHOLDER":

        user_token = hue.create_user()

        if user_token == "link button not pressed":

            return redirect(url_for(".index"))

        app_config.save("user_token", user_token)

    return redirect(url_for(".index"))
Exemplo n.º 6
0
def create_user():

    conf = app_config.get()

    url = "http://" + conf["bridge_ip"] + "/api"

    json_data = {"devicetype": conf["hue_device_name"]}

    params = json.dumps(json_data).encode('utf8')

    req = api.Request(url, data=params, method="POST")

    response = api.urlopen(req).read().decode()

    status = json.loads(response)[0]

    if "success" in status:

        return str(status["success"]["username"])

    elif "error" in status:

        return str(status["error"]["description"])
Exemplo n.º 7
0
def get_state(sport):

    conf = app_config.get()

    alert_type, alert_id = conf[sport + "_alert_selection_type"], conf[
        sport + "_alert_selection_id"]

    url = "http://" + conf["bridge_ip"] + "/api/" + conf[
        "user_token"] + "/" + alert_type + "/" + alert_id

    response_json = json.loads(api.urlopen(url).read().decode())

    hue_state = response_json["state"] if conf[
        sport +
        "_alert_selection_type"] == "lights" else response_json["action"]

    current_state = {
        "on": hue_state["on"],
        "sat": hue_state["sat"],
        "bri": hue_state["bri"],
        "hue": hue_state["hue"]
    }

    return current_state
Exemplo n.º 8
0
def get_html():

    return Markup(render_template('packages/dashboard.html', selections=app_config.get()))