def wait_for_all_stations():
    """
    Waits for all of the airports to have been given a chance to initialize.
    If an airport had an error, then that still counts.
    """

    for airport in stations:
        try:
            weather.get_metar(airport)
        except Exception as ex:
            safe_logging.safe_log_warning(
                "Error while initializing with airport={}, EX={}".format(airport, ex))

    return True
    def render_station(self, station: str, is_blink: bool = False):
        """
        Sets the LED for a station.
        This is a default, empty, implementation meant to be overridden
        and simply define the interface.

        Args:
            renderer (Renderer): [description]
            airport (str): [description]
            is_blink (bool, optional): [description]. Defaults to False.
        """
        condition, blink = get_airport_condition(station)
        color_name_by_category = get_color_from_condition(condition)
        color_by_category = rgb_colors[color_name_by_category]

        if is_blink:
            metar = weather.get_metar(station)
            is_lightning = weather.is_lightning(metar)

            if is_lightning:
                color_by_category = rgb_colors[colors_lib.YELLOW]

        if blink and is_blink:
            color_by_category = rgb_colors[colors_lib.OFF]

        color_to_render = self.__get_brightness_adjusted_color__(
            station, color_by_category)

        self.__renderer__.set_leds(self.__stations__[station], color_to_render)
    def render_station(self, station: str, is_blink: bool = False):
        """
        Renders a station based on the pressure.

        Arguments:
            station {string} -- The identifier of the station.
        """

        metar = weather.get_metar(station)
        pressure = weather.get_pressure(metar)
        color_to_render = get_color_by_pressure(pressure)
        final_color = colors_lib.get_brightness_adjusted_color(
            color_to_render, configuration.get_brightness_proportion())

        self.__renderer__.set_leds(self.__stations__[station], final_color)
    def render_station(self, station: str, is_blink: bool = False):
        """
        Renders an airport.

        Arguments:
            airport {string} -- The identifier of the station.
        """

        metar = weather.get_metar(station)
        temperature = weather.get_temperature(metar)
        color_to_render = get_color_by_temperature_celsius(temperature)
        final_color = self.__get_brightness_adjusted_color__(
            station, color_to_render)

        self.__renderer__.set_leds(self.__stations__[station], final_color)
示例#5
0
def update_station_categorization(airport, utc_offset):
    """
    Updates the categorization for a single given station.

    Arguments:
        airport {string} -- The identifier of the weather station.
        utc_offset {int} -- The number of hours off from UTC the station is.
    """

    try:
        metar = weather.get_metar(airport, logger=LOGGER)
        category = get_airport_category(airport, metar, utc_offset)
        set_airport_display(airport, category, metar=metar)
    except Exception as e:
        safe_log_warning(
            LOGGER,
            'While attempting to get category for {}, got EX:{}'.format(airport, e))
    def render_station(self, station: str, is_blink: bool = False):
        """
        Renders a station based on any precipitation found in the metar.

        Arguments:
            station {string} -- The identifier of the station.
        """

        metar = weather.get_metar(station)
        precipitation = weather.get_precipitation(metar)
        color_to_render, blink = get_color_by_precipitation(precipitation)
        final_color = self.__get_brightness_adjusted_color__(
            station, color_to_render)

        # Turn the LED off for the blink
        if is_blink and blink:
            final_color = colors_lib.get_brightness_adjusted_color(
                final_color, 0.0)

        self.__renderer__.set_leds(self.__stations__[station], final_color)
示例#7
0
def wait_for_all_airports():
    """
    Waits for all of the airports to have been given a chance to initialize.
    If an airport had an error, then that still counts.
    """

    utc_offset = datetime.utcnow() - datetime.now()

    for airport in airport_render_config:
        try:
            thread_lock_object.acquire()
            metar = weather.get_metar(airport, logger=LOGGER)
            category = get_airport_category(airport, metar, utc_offset)
            airport_conditions[airport] = (category, False)
        except:
            airport_conditions[airport] = (weather.INVALID, False)
            safe_log_warning(
                LOGGER, "Error while initializing with airport=" + airport)
        finally:
            thread_lock_object.release()

    return True
def get_airport_condition(airport: str) -> str:
    """
    Sets the given airport to have the given flight rules category.

    Arguments:
        airport {str} -- The airport identifier.
        category {string} -- The flight rules category.

    Returns:
        bool -- True if the flight category changed (or was set for the first time).
    """

    try:
        metar = weather.get_metar(airport)
        category = get_airport_category(airport, metar)
        should_flash = should_station_flash(metar)

        return category, should_flash
    except Exception as ex:
        safe_logging.safe_log_warning(
            'set_airport_display() - {} - EX:{}'.format(airport, ex))

        return weather.INOP, True
    # Validate that the station is in the CSV file
    try:
        data_file_icao_code = weather.get_faa_csv_identifier(station_id)
    except Exception as e:
        terminal_error(
            'Unable to fetch the station {} from the CSV data file. Please check that the station is in the CSV file. Error={}'
            .format(station_id, e))

    if data_file_icao_code is None or data_file_icao_code == '' or weather.INVALID in data_file_icao_code:
        terminal_error(
            'Unable to fetch the station {} from the CSV data file. Please check that the station is in the CSV file. Error={}'
            .format(station_id, e))

    # Validate that the station can have weather fetched
    metar = weather.get_metar(station_id, logger=LOGGER)

    if metar is None or weather.INVALID in metar:
        stations_unable_to_fetch_weather.append(station_id)
        safe_log_warning(
            LOGGER,
            'Unable to fetch weather for {}/{}'.format(station_id, led_index))

    # Validate that the station can have Sunrise/Sunset fetched
    day_night_info = weather.get_civil_twilight(station_id)

    if day_night_info is None:
        terminal_error('Unable to fetch day/night info for {}/{}'.format(
            station_id, led_index))

    if len(day_night_info) != 6:
    # Validate that the station is in the CSV file
    try:
        data_file_icao_code = weather.get_faa_csv_identifier(station_id)
    except Exception as e:
        terminal_error(
            'Unable to fetch the station {} from the CSV data file. Please check that the station is in the CSV file. Error={}'.format(station_id, e))

    if data_file_icao_code is None or data_file_icao_code == '' or weather.INVALID in data_file_icao_code:
        terminal_error(
            'Unable to fetch the station {} from the CSV data file. Please check that the station is in the CSV file. Error={}'.format(
                station_id,
                e))

    # Validate that the station can have weather fetched
    metar = weather.get_metar(station_id)

    if metar is None or weather.INVALID in metar:
        stations_unable_to_fetch_weather.append(station_id)
        safe_logging.safe_log_warning(
            'Unable to fetch weather for {}/{}'.format(
                station_id,
                led_indices))

    # Validate that the station can have Sunrise/Sunset fetched
    day_night_info = weather.get_civil_twilight(station_id)

    if day_night_info is None:
        terminal_error(
            'Unable to fetch day/night info for {}/{}'.format(
                station_id,