mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Fix retry when Met config entry fails (#70012)
This commit is contained in:
parent
f5318ef6c2
commit
0f8595e8a7
@ -21,6 +21,7 @@ from homeassistant.const import (
|
|||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant
|
from homeassistant.core import Event, HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.util.distance import convert as convert_distance
|
from homeassistant.util.distance import convert as convert_distance
|
||||||
@ -33,6 +34,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Dedicated Home Assistant endpoint - do not change!
|
||||||
URL = "https://aa015h6buqvih86i1.api.met.no/weatherapi/locationforecast/2.0/complete"
|
URL = "https://aa015h6buqvih86i1.api.met.no/weatherapi/locationforecast/2.0/complete"
|
||||||
|
|
||||||
PLATFORMS = [Platform.WEATHER]
|
PLATFORMS = [Platform.WEATHER]
|
||||||
@ -82,6 +84,10 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
class CannotConnect(HomeAssistantError):
|
||||||
|
"""Unable to connect to the web site."""
|
||||||
|
|
||||||
|
|
||||||
class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]):
|
class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]):
|
||||||
"""Class to manage fetching Met data."""
|
"""Class to manage fetching Met data."""
|
||||||
|
|
||||||
@ -173,7 +179,9 @@ class MetWeatherData:
|
|||||||
|
|
||||||
async def fetch_data(self) -> MetWeatherData:
|
async def fetch_data(self) -> MetWeatherData:
|
||||||
"""Fetch data from API - (current weather and forecast)."""
|
"""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()
|
self.current_weather_data = self._weather_data.get_current_weather()
|
||||||
time_zone = dt_util.DEFAULT_TIME_ZONE
|
time_zone = dt_util.DEFAULT_TIME_ZONE
|
||||||
self.daily_forecast = self._weather_data.get_forecast(time_zone, False)
|
self.daily_forecast = self._weather_data.get_forecast(time_zone, False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user