def extra_state_attributes(self): """Return the state attributes.""" return { **readeable_phenomenoms_dict(self.coordinator.data.phenomenons_max_colors), ATTR_ATTRIBUTION: ATTRIBUTION, }
def test_workflow(city: str) -> None: """Test classical workflow usage with the Python library.""" # Init client client = MeteoFranceClient() # Search a location from name. list_places = client.search_places(city) if (len(list_places) > 0) : my_place = list_places[0] else : print("Rien trouvé") return "" # Fetch weather forecast for the location my_place_weather_forecast = client.get_forecast_for_place(my_place) # Get the daily forecast my_place_daily_forecast = my_place_weather_forecast.daily_forecast # Fetch weather alerts. if my_place.admin2: my_place_weather_alerts = client.get_warning_current_phenomenoms( my_place.admin2 ) readable_warnings = readeable_phenomenoms_dict( my_place_weather_alerts.phenomenons_max_colors ) return [my_place, readable_warnings["Neige-verglas"], my_place_daily_forecast]
def test_readeable_phenomenoms_dict() -> None: """Test the helper constructing a human readable dictionary for phenomenom.""" api_list = [ {"phenomenon_id": 4, "phenomenon_max_color_id": 1}, {"phenomenon_id": 5, "phenomenon_max_color_id": 1}, {"phenomenon_id": 3, "phenomenon_max_color_id": 2}, {"phenomenon_id": 2, "phenomenon_max_color_id": 1}, {"phenomenon_id": 1, "phenomenon_max_color_id": 3}, ] expected_dictionary = { "Inondation": "Vert", "Neige-verglas": "Vert", "Pluie-inondation": "Vert", "Orages": "Jaune", "Vent violent": "Orange", } assert readeable_phenomenoms_dict(api_list) == expected_dictionary
def test_workflow(city: str) -> None: """Test classical workflow usage with the Python library.""" # Init client client = MeteoFranceClient() # Search a location from name. list_places = client.search_places(city) my_place = list_places[0] # Fetch weather forecast for the location my_place_weather_forecast = client.get_forecast_for_place(my_place) # Get the daily forecast my_place_daily_forecast = my_place_weather_forecast.daily_forecast # If rain in the hour forecast is available, get it. if my_place_weather_forecast.position["rain_product_available"] == 1: my_place_rain_forecast = client.get_rain(my_place.latitude, my_place.longitude) next_rain_dt = my_place_rain_forecast.next_rain_date_locale() if not next_rain_dt: rain_status = "No rain expected in the following hour." else: rain_status = next_rain_dt.strftime("%H:%M") else: rain_status = "No rain forecast available." # Fetch weather alerts. if my_place.admin2: my_place_weather_alerts = client.get_warning_current_phenomenoms( my_place.admin2 ) readable_warnings = readeable_phenomenoms_dict( my_place_weather_alerts.phenomenons_max_colors ) assert type(my_place_daily_forecast) == list assert rain_status assert type(readable_warnings) == dict