From 0f8595e8a7e8b423f3dd7205b9aa84a11830fcf1 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Sat, 16 Apr 2022 18:04:09 +0200 Subject: [PATCH] Fix retry when Met config entry fails (#70012) --- homeassistant/components/met/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/met/__init__.py b/homeassistant/components/met/__init__.py index 536cf03bde2..2f663df458e 100644 --- a/homeassistant/components/met/__init__.py +++ b/homeassistant/components/met/__init__.py @@ -21,6 +21,7 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import Event, HomeAssistant +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.util.distance import convert as convert_distance @@ -33,6 +34,7 @@ from .const import ( DOMAIN, ) +# Dedicated Home Assistant endpoint - do not change! URL = "https://aa015h6buqvih86i1.api.met.no/weatherapi/locationforecast/2.0/complete" PLATFORMS = [Platform.WEATHER] @@ -82,6 +84,10 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> return unload_ok +class CannotConnect(HomeAssistantError): + """Unable to connect to the web site.""" + + class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]): """Class to manage fetching Met data.""" @@ -173,7 +179,9 @@ class MetWeatherData: async def fetch_data(self) -> MetWeatherData: """Fetch data from API - (current weather and forecast).""" - await self._weather_data.fetching_data() + resp = await self._weather_data.fetching_data() + if not resp: + raise CannotConnect() self.current_weather_data = self._weather_data.get_current_weather() time_zone = dt_util.DEFAULT_TIME_ZONE self.daily_forecast = self._weather_data.get_forecast(time_zone, False)