示例#1
0
文件: webfun.py 项目: sophem/mittrom
def light_status(secret):
    """Makes it check the status of the lights"""
    if not access(request.url, secret, "Sjekket status"): return "No."

    Light.refresh()
    target_light = request.args.get("target_light")
    light = Light.find_light(target_light)
    if light:
        # hvis vi kommer hit, så vet vi at vi har funnet lyset
        if light.on:
            return "Lyset er på. :-)"

        return "Lyset er av."

    return "Fant ikke lyset."
示例#2
0
文件: webfun.py 项目: sophem/mittrom
def light_set(secret):
    """Turn on or off a specific light"""
    if not access(request.url, secret): return "No."

    Light.refresh()
    user = access(request.url, secret)
    if not user: return "No."
    tell_sophie(f"{user} så status på lys")

    target_light = request.args.get("target_light")
    target_status = str(
        request.args.get("target_status")).lower() in ["on", "true"]
    light = Light.find_light(target_light)

    if light:
        tell_sophie(f"{user}: satt {target_light} til {target_status}")
        light.set_state(target_status)

        return "Skrudde lyset på" if target_status else "Skrudde lyset av"

    return "Fant ikke lyset."