def home(): if is_local_request(flask.request): home_status = get_home_status(template_friendly_dict=True) # Template engine requires string values guest_mode = "true" if env.is_guest_mode() else "false" party_mode = "true" if env.is_party_mode() else "false" return flask.render_template("home.html", home_status=home_status, guest_mode=guest_mode, party_mode=party_mode) else: logger.info("Home accessed by remote address %s", flask.request.environ["REMOTE_ADDR"]) flask.abort(404)
def party(): global party_process json = flask.request.get_json() enabled = json.get("enabled", False) logger.info("Got party state %r" % enabled) if enabled and not env.is_party_mode(): # Start party XD party_process = Popen(["python3", "./animate_web.py", "run"]) # async env.set_party_mode(True) elif not enabled and env.is_party_mode(): # Stop party :( env.set_party_mode(False) if party_process is not None: party_process.kill() party_process = None # Return lights to circadian color command = copy.deepcopy(COMMAND_FULL_ON) circadian_color = get_current_circadian_color(date=get_local_time()) command_all_lights(circadian_color.apply_to_command(command)) return "Party mode is now %r" % enabled