mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Fix Airly asyncio timeout error (#28387)
* Raise ConfigEntryNotReady * Better asyncio.TimeoutError handling * Sort imports * Increase asyncio timeout
This commit is contained in:
parent
ff5b070f4b
commit
d133501735
@ -1,15 +1,16 @@
|
|||||||
"""The Airly component."""
|
"""The Airly component."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
import async_timeout
|
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
from airly import Airly
|
from airly import Airly
|
||||||
from airly.exceptions import AirlyError
|
from airly.exceptions import AirlyError
|
||||||
|
import async_timeout
|
||||||
|
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
||||||
from homeassistant.core import Config, HomeAssistant
|
from homeassistant.core import Config, HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
@ -45,6 +46,9 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
await airly.async_update()
|
await airly.async_update()
|
||||||
|
|
||||||
|
if not airly.data:
|
||||||
|
raise ConfigEntryNotReady()
|
||||||
|
|
||||||
hass.data[DOMAIN] = {}
|
hass.data[DOMAIN] = {}
|
||||||
hass.data[DOMAIN][DATA_CLIENT] = {}
|
hass.data[DOMAIN][DATA_CLIENT] = {}
|
||||||
hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id] = airly
|
hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id] = airly
|
||||||
@ -81,7 +85,7 @@ class AirlyData:
|
|||||||
"""Update Airly data."""
|
"""Update Airly data."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with async_timeout.timeout(10):
|
with async_timeout.timeout(20):
|
||||||
measurements = self.airly.create_measurements_session_point(
|
measurements = self.airly.create_measurements_session_point(
|
||||||
self.latitude, self.longitude
|
self.latitude, self.longitude
|
||||||
)
|
)
|
||||||
@ -104,11 +108,8 @@ class AirlyData:
|
|||||||
self.data[ATTR_API_CAQI_DESCRIPTION] = index["description"]
|
self.data[ATTR_API_CAQI_DESCRIPTION] = index["description"]
|
||||||
self.data[ATTR_API_ADVICE] = index["advice"]
|
self.data[ATTR_API_ADVICE] = index["advice"]
|
||||||
_LOGGER.debug("Data retrieved from Airly")
|
_LOGGER.debug("Data retrieved from Airly")
|
||||||
except (
|
except asyncio.TimeoutError:
|
||||||
ValueError,
|
_LOGGER.error("Asyncio Timeout Error")
|
||||||
AirlyError,
|
except (ValueError, AirlyError, ClientConnectorError) as error:
|
||||||
asyncio.TimeoutError,
|
|
||||||
ClientConnectorError,
|
|
||||||
) as error:
|
|
||||||
_LOGGER.error(error)
|
_LOGGER.error(error)
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user