Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from thebino/Bugfix/TimeoutSpan
Browse files Browse the repository at this point in the history
increase timeout span for fetching data
  • Loading branch information
thebino authored Apr 20, 2021
2 parents c14518b + be6ca39 commit 1dc16c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions custom_components/rki_covid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ async def async_get_districts():
"""
_LOGGER.debug("fetch data from rki-covid-parser.")
try:
with async_timeout.timeout(10):
with async_timeout.timeout(30):
# return {case.county: case for case in await api.load_districts()}
await parser.load_data()
_LOGGER.debug("fetching finished.")

items = {}

Expand Down Expand Up @@ -139,11 +140,16 @@ async def async_get_districts():
parser.country.lastUpdate,
)

_LOGGER.debug("parsing data finished.")
return items

except (asyncio.TimeoutError, aiohttp.ClientError) as err:
except asyncio.TimeoutError as err:
raise update_coordinator.UpdateFailed(
f"Error reading data from rki-covid-parser: {err}"
f"Error reading data from rki-covid-parser timed-out: {err}"
)
except aiohttp.ClientError as err:
raise update_coordinator.UpdateFailed(
f"Error reading data from rki-covid-parser by client: {err}"
)

hass.data[DOMAIN] = update_coordinator.DataUpdateCoordinator(
Expand Down
7 changes: 7 additions & 0 deletions custom_components/rki_covid/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant import config_entries, core
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers import update_coordinator
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -72,6 +73,9 @@ async def async_setup_platform(
parser = RkiCovidParser(session)
coordinator = await get_coordinator(hass, parser)

if coordinator is None or coordinator.data is None:
raise PlatformNotReady("Data coordinator could not be initialized!")

districts = config[CONF_DISTRICTS]

sensors = [
Expand All @@ -93,6 +97,9 @@ async def async_setup_entry(
parser = RkiCovidParser(session)
coordinator = await get_coordinator(hass, parser)

if coordinator is None or coordinator.data is None:
raise PlatformNotReady("Data coordinator could not be initialized!")

try:
district = config_entry.data[ATTR_COUNTY]
except KeyError:
Expand Down

0 comments on commit 1dc16c5

Please sign in to comment.