Beispiel #1
0
def _handle_brightness_request(device: str,
                               request: WSGIRequest) -> HttpResponse:
    value, response = extract_value(request.POST)
    assert device in ["ring", "strip", "wled", "screen"]
    storage.put(cast(DeviceBrightness, f"{device}_brightness"), float(value))
    _notify_settings_changed(device)
    return response
Beispiel #2
0
def set_volume(request: WSGIRequest) -> HttpResponse:
    """Sets the playback volume.
    value has to be a float between 0 and 1."""
    volume, response = extract_value(request.POST)
    _set_volume(float(volume))
    storage.put("volume", float(volume))
    return response
Beispiel #3
0
def set_wled_port(request: WSGIRequest) -> HttpResponse:
    """Updates the wled port."""
    value, response = extract_value(request.POST)
    if not 1024 <= int(value) <= 65535:
        return HttpResponseBadRequest("invalid port")
    storage.put("wled_port", int(value))
    _notify_settings_changed("wled")
    return response
Beispiel #4
0
def set_wled_led_count(request: WSGIRequest) -> HttpResponse:
    """Updates the wled led_count."""
    value, response = extract_value(request.POST)
    if not 2 <= int(value) <= 490:
        return HttpResponseBadRequest("must be between 2 and 490")
    storage.put("wled_led_count", int(value))
    _notify_settings_changed("wled")
    return response
Beispiel #5
0
def _handle_monochrome_request(device: str,
                               request: WSGIRequest) -> HttpResponse:
    value, response = extract_value(request.POST)
    assert device in ["ring", "strip", "wled", "screen"]
    storage.put(cast(DeviceMonochrome, f"{device}_monochrome"),
                strtobool(value))
    _notify_settings_changed(device)
    return response
Beispiel #6
0
def _handle_program_request(device: str, request: WSGIRequest) -> HttpResponse:
    program, response = extract_value(request.POST)
    assert device in ["ring", "strip", "wled", "screen"]
    if program == storage.get(cast(DeviceProgram, f"{device}_program")):
        # the program doesn't change, return immediately
        return HttpResponse()
    set_program(device, program)
    return response
Beispiel #7
0
def set_initial_resolution(request: WSGIRequest) -> HttpResponse:
    """Sets the resolution used on the screen."""
    value, response = extract_value(request.POST)
    resolution = tuple(map(int, value.split("x")))
    resolution = cast(Tuple[int, int], resolution)
    storage.put("initial_resolution", resolution)
    # adjusting sets the resolution and restarts the screen program
    _notify_settings_changed("adjust_screen")
    return response
Beispiel #8
0
def set_wled_ip(request: WSGIRequest) -> HttpResponse:
    """Updates the wled ip."""
    value, response = extract_value(request.POST)
    try:
        socket.inet_aton(value)
    except socket.error:
        return HttpResponseBadRequest("invalid ip")
    storage.put("wled_ip", value)
    _notify_settings_changed("wled")
    return response
Beispiel #9
0
def set_interactivity(request: WSGIRequest) -> HttpResponse:
    """Enables or disables voting based on the given value."""
    value, response = extract_value(request.POST)
    if value not in [
        getattr(storage.Interactivity, attr)
        for attr in dir(storage.Interactivity)
        if not attr.startswith("__")
    ]:
        return HttpResponseBadRequest("Invalid value")
    storage.put("interactivity", value)
    return response
Beispiel #10
0
def set_fixed_color(request: WSGIRequest) -> HttpResponse:
    """Updates the static color used for some programs."""
    hex_col, response = extract_value(request.POST)
    hex_col = hex_col.lstrip("#")
    try:
        color = tuple(int(hex_col[i:i + 2], 16) / 255 for i in (0, 2, 4))
    except IndexError:
        return HttpResponseBadRequest("color needs to be in #rrggbb format")
    # https://github.com/python/mypy/issues/5068
    color = cast(Tuple[float, float, float], color)
    storage.put("fixed_color", color)
    _notify_settings_changed("base")
    return response
Beispiel #11
0
def set_lights_shortcut(request: WSGIRequest) -> HttpResponse:
    """Stores the current lights state and restores the previous one."""
    value, response = extract_value(request.POST)
    should_enable = strtobool(value)
    is_enabled = (storage.get("ring_program") != "Disabled"
                  or storage.get("wled_program") != "Disabled"
                  or storage.get("strip_program") != "Disabled")
    if should_enable == is_enabled:
        return HttpResponse()
    if should_enable:
        for device in ["ring", "wled", "strip"]:
            set_program(
                device,
                storage.get(cast(DeviceProgram, f"last_{device}_program")))
    else:
        for device in ["ring", "wled", "strip"]:
            set_program(device, "Disabled")
    return response
Beispiel #12
0
def set_max_queue_length(request: WSGIRequest) -> HttpResponse:
    """Sets the maximum number of songs that are downloaded from a playlist."""
    value, response = extract_value(request.POST)
    storage.put("max_queue_length", int(value))
    return response
Beispiel #13
0
def set_forbidden_keywords(request: WSGIRequest) -> HttpResponse:
    """Sets the keywords to filter out of results."""
    value, response = extract_value(request.POST)
    storage.put("forbidden_keywords", value)
    return response
Beispiel #14
0
def set_song_cooldown(request: WSGIRequest) -> HttpResponse:
    """Enables or disables the new music only mode based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("song_cooldown", float(value))
    return response
Beispiel #15
0
def set_max_download_size(request: WSGIRequest) -> HttpResponse:
    """Sets the maximum amount of MB that are allowed for a song that needs to be downloaded."""
    value, response = extract_value(request.POST)
    storage.put("max_download_size", float(value))
    return response
Beispiel #16
0
def set_dynamic_resolution(request: WSGIRequest) -> HttpResponse:
    """Sets whether the resolution should be dynamically adjusted depending on the performance."""
    value, response = extract_value(request.POST)
    storage.put("dynamic_resolution", strtobool(value))
    _notify_settings_changed("base")
    return response
Beispiel #17
0
def set_dynamic_embedded_stream(request: WSGIRequest) -> HttpResponse:
    """Enables or disables dynamic streaming based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("dynamic_embedded_stream", strtobool(value))
    return response
Beispiel #18
0
def set_downvotes_to_kick(request: WSGIRequest) -> HttpResponse:
    """Sets the number of downvotes that are needed to remove a song from the queue."""
    value, response = extract_value(request.POST)
    storage.put("downvotes_to_kick", int(value))
    return response
Beispiel #19
0
def set_people_to_party(request: WSGIRequest) -> HttpResponse:
    """Sets the amount of active clients needed to enable partymode."""
    value, response = extract_value(request.POST)
    storage.put("people_to_party", int(value))
    return response
Beispiel #20
0
def set_buzzer_cooldown(request: WSGIRequest) -> HttpResponse:
    """Sets the minimum time that needs to pass between buzzer presses."""
    value, response = extract_value(request.POST)
    storage.put("buzzer_cooldown", float(value))
    return response
Beispiel #21
0
def set_alarm_probability(request: WSGIRequest) -> HttpResponse:
    """Sets the probability with which an alarm is triggered after each song."""
    value, response = extract_value(request.POST)
    storage.put("alarm_probability", float(value))
    return response
Beispiel #22
0
def set_program_speed(request: WSGIRequest) -> HttpResponse:
    """Updates the global speed of programs supporting it."""
    value, response = extract_value(request.POST)
    storage.put("program_speed", float(value))
    _notify_settings_changed("base")
    return response
Beispiel #23
0
def set_buzzer_success_probability(request: WSGIRequest) -> HttpResponse:
    """Sets the probability for the buzzer to play a success sound."""
    value, response = extract_value(request.POST)
    storage.put("buzzer_success_probability", float(value))
    return response
Beispiel #24
0
def set_number_of_suggestions(request: WSGIRequest) -> HttpResponse:
    """Set the number of archived suggestions based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("number_of_suggestions", int(value))
    return response
Beispiel #25
0
def set_ip_checking(request: WSGIRequest) -> HttpResponse:
    """Enables or disables ip checking based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("ip_checking", strtobool(value))
    return response
Beispiel #26
0
def set_connectivity_host(request: WSGIRequest) -> HttpResponse:
    """Sets the host that is pinged to check the internet connection."""
    value, response = extract_value(request.POST)
    storage.put("connectivity_host", value)
    return response
Beispiel #27
0
def set_embed_stream(request: WSGIRequest) -> HttpResponse:
    """Enables or disables logging of requests and play logs based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("embed_stream", strtobool(value))
    return response
Beispiel #28
0
def set_enqueue_first(request: WSGIRequest) -> HttpResponse:
    """Enables or disables the new music only mode based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("enqueue_first", strtobool(value))
    return response
Beispiel #29
0
def set_online_suggestions(request: WSGIRequest) -> HttpResponse:
    """Enables or disables online suggestions based on the given value."""
    value, response = extract_value(request.POST)
    storage.put("online_suggestions", strtobool(value))
    return response
Beispiel #30
0
def set_youtube_suggestions(request: WSGIRequest) -> HttpResponse:
    """Sets the number of online suggestions from youtube to be shown."""
    value, response = extract_value(request.POST)
    storage.put("youtube_suggestions", int(value))
    return response