def get_color_from_condition(category):
    """
    From a condition, returns the color it should be rendered as, and if it should flash.

    Arguments:
        category {string} -- The weather category (VFR, IFR, et al.)

    Returns:
        [tuple] -- The color (also a tuple) and if it should blink.
    """

    if category == weather.VFR:
        return (weather.GREEN, False)
    elif category == weather.MVFR:
        return (weather.BLUE, False)
    elif category == weather.IFR:
        return (weather.RED, False)
    elif category == weather.LIFR:
        # Only blink for normal LEDs.
        # PWM and WS2801 have their own color.
        return (weather.LOW, configuration.get_mode() == configuration.STANDARD)
    elif category == weather.NIGHT:
        return (weather.YELLOW, False)

    ## Error
    return (weather.WHITE, True)
Example #2
0
def get_mix_and_color(color_by_category, airport):
    """
    Gets the proportion of color mixes (dark to NIGHT, NIGHT to color) and the final color to render.

    Arguments:
        color_by_category {tuple} -- the initial color decided upon by weather.
        airport {string} -- The station identifier.

    Returns:
        tuple -- proportion, color to render
    """

    color_to_render = color_by_category
    proportions = weather.get_twilight_transition(airport)

    if configuration.get_night_lights():
        if proportions[0] <= 0.0 and proportions[1] <= 0.0:
            color_to_render = colors[weather.DARK_YELLOW]
        # Do not allow color mixing for standard LEDs
        # Instead if we are going to render NIGHT then
        # have the NIGHT color represent that the station
        # is in a twilight period.
        elif configuration.get_mode() == configuration.STANDARD:
            if proportions[0] > 0.0 or proportions[1] < 1.0:
                color_to_render = color_by_rules[weather.NIGHT]
            elif proportions[0] <= 0.0 and proportions[1] <= 0.0:
                color_to_render = colors[weather.DARK_YELLOW]
        elif proportions[0] > 0.0:
            color_to_render = colors_lib.get_color_mix(
                colors[weather.DARK_YELLOW], color_by_rules[weather.NIGHT], proportions[0])
        elif proportions[1] > 0.0:
            color_to_render = colors_lib.get_color_mix(
                color_by_rules[weather.NIGHT], color_by_category, proportions[1])
    return proportions, color_to_render
def get_color_from_condition(
    category,
    metar=None
):
    """
    From a condition, returns the color it should be rendered as, and if it should flash.

    Arguments:
        category {string} -- The weather category (VFR, IFR, et al.)

    Returns:
        [tuple] -- The color (also a tuple) and if it should blink.
    """

    is_old = False
    metar_age = None

    if metar is not None and metar != weather.INVALID:
        metar_age = weather.get_metar_age(metar)

    if metar_age is not None:
        metar_age_minutes = metar_age.total_seconds() / 60.0
        safe_log(LOGGER,
                 "{} - Issued {:.1f} minutes ago".format(category, metar_age_minutes))

        is_old = metar_age_minutes > weather.DEFAULT_METAR_INVALIDATE_MINUTES
        is_inactive = metar_age_minutes > weather.DEFAULT_METAR_STATION_INACTIVE
    else:
        is_inactive = True

    # No report for a while?
    # Count the station as INOP.
    # The default is to follow what ForeFlight and SkyVector
    # do and just turn it off.
    if is_inactive:
        return (weather.INOP, False)

    if category == weather.VFR:
        return (weather.GREEN, is_old)
    elif category == weather.MVFR:
        return (weather.BLUE, is_old)
    elif category == weather.IFR:
        return (weather.RED, is_old)
    elif category == weather.LIFR:
        # Only blink for normal LEDs.
        # PWM and WS2801 have their own color.
        return (weather.LOW, configuration.get_mode() == configuration.STANDARD)
    elif category == weather.NIGHT:
        return (weather.YELLOW, False)
    elif category == weather.SMOKE:
        return (weather.GRAY, is_old)

    # Error
    return (weather.OFF, False)
Example #4
0
def get_test_renderer():
    """
    Returns the renderer to use based on the type of
    LED lights given in the config.

    Returns:
        renderer -- Object that takes the colors and airport config and
        sets the LEDs.
    """

    if configuration.get_mode() == configuration.WS2801:
        pixel_count = configuration.CONFIG["pixel_count"]
        spi_port = configuration.CONFIG["spi_port"]
        spi_device = configuration.CONFIG["spi_device"]

        return ws2801.Ws2801Renderer(pixel_count, spi_port, spi_device)
    elif configuration.get_mode() == configuration.PWM:
        return led_pwm.LedPwmRenderer(airport_render_config)
    else:
        # "Normal" LEDs
        return led.LedRenderer(airport_render_config)
def get_test_renderer():
    if configuration.get_mode() == configuration.WS2811:
        pixel_count = configuration.CONFIG["pixel_count"]
        port = configuration.CONFIG["gpio_port"]
        return ws2811.Ws2811Renderer(pixel_count, port)