Use builtin TimeoutError [misc] (#109703)
This commit is contained in:
parent
5dfffb0818
commit
46f8fb3ac1
14 changed files with 14 additions and 31 deletions
|
@ -1,5 +1,4 @@
|
|||
"""The Bond integration."""
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
from http import HTTPStatus
|
||||
import logging
|
||||
from typing import Any
|
||||
|
@ -56,7 +55,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
_LOGGER.error("Bond token no longer valid: %s", ex)
|
||||
return False
|
||||
raise ConfigEntryNotReady from ex
|
||||
except (ClientError, AsyncIOTimeoutError, OSError) as error:
|
||||
except (ClientError, TimeoutError, OSError) as error:
|
||||
raise ConfigEntryNotReady from error
|
||||
|
||||
bpup_subs = BPUPSubscriptions()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from asyncio import Lock, TimeoutError as AsyncIOTimeoutError
|
||||
from asyncio import Lock
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
|
@ -139,7 +139,7 @@ class BondEntity(Entity):
|
|||
"""Fetch via the API."""
|
||||
try:
|
||||
state: dict = await self._hub.bond.device_state(self._device_id)
|
||||
except (ClientError, AsyncIOTimeoutError, OSError) as error:
|
||||
except (ClientError, TimeoutError, OSError) as error:
|
||||
if self.available:
|
||||
_LOGGER.warning(
|
||||
"Entity %s has become unavailable", self.entity_id, exc_info=error
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Config flow for Control4 integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as asyncioTimeoutError
|
||||
import logging
|
||||
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
|
@ -82,7 +81,7 @@ class Control4Validator:
|
|||
)
|
||||
await director.getAllItemInfo()
|
||||
return True
|
||||
except (Unauthorized, ClientError, asyncioTimeoutError):
|
||||
except (Unauthorized, ClientError, TimeoutError):
|
||||
_LOGGER.error("Failed to connect to the Control4 controller")
|
||||
return False
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""The Nightscout integration."""
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
|
||||
from aiohttp import ClientError
|
||||
from py_nightscout import Api as NightscoutAPI
|
||||
|
@ -26,7 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
api = NightscoutAPI(server_url, session=session, api_secret=api_key)
|
||||
try:
|
||||
status = await api.get_server_status()
|
||||
except (ClientError, AsyncIOTimeoutError, OSError) as error:
|
||||
except (ClientError, TimeoutError, OSError) as error:
|
||||
raise ConfigEntryNotReady from error
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Config flow for Nightscout integration."""
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
|
@ -30,7 +29,7 @@ async def _validate_input(data: dict[str, Any]) -> dict[str, str]:
|
|||
await api.get_sgvs()
|
||||
except ClientResponseError as error:
|
||||
raise InputValidationError("invalid_auth") from error
|
||||
except (ClientError, AsyncIOTimeoutError, OSError) as error:
|
||||
except (ClientError, TimeoutError, OSError) as error:
|
||||
raise InputValidationError("cannot_connect") from error
|
||||
|
||||
# Return info to be stored in the config entry.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Nightscout sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
@ -51,7 +50,7 @@ class NightscoutSensor(SensorEntity):
|
|||
"""Fetch the latest data from Nightscout REST API and update the state."""
|
||||
try:
|
||||
values = await self.api.get_sgvs()
|
||||
except (ClientError, AsyncIOTimeoutError, OSError) as error:
|
||||
except (ClientError, TimeoutError, OSError) as error:
|
||||
_LOGGER.error("Error fetching data. Failed with %s", error)
|
||||
self._attr_available = False
|
||||
return
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""The OurGroceries integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
|
||||
from aiohttp import ClientError
|
||||
from ourgroceries import OurGroceries
|
||||
from ourgroceries.exceptions import InvalidLoginException
|
||||
|
@ -26,7 +24,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
og = OurGroceries(data[CONF_USERNAME], data[CONF_PASSWORD])
|
||||
try:
|
||||
await og.login()
|
||||
except (AsyncIOTimeoutError, ClientError) as error:
|
||||
except (TimeoutError, ClientError) as error:
|
||||
raise ConfigEntryNotReady from error
|
||||
except InvalidLoginException:
|
||||
return False
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Config flow for OurGroceries integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
|
@ -40,7 +39,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
og = OurGroceries(user_input[CONF_USERNAME], user_input[CONF_PASSWORD])
|
||||
try:
|
||||
await og.login()
|
||||
except (AsyncIOTimeoutError, ClientError):
|
||||
except (TimeoutError, ClientError):
|
||||
errors["base"] = "cannot_connect"
|
||||
except InvalidLoginException:
|
||||
errors["base"] = "invalid_auth"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Common methods used across tests for Bond."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
from contextlib import nullcontext
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
@ -248,7 +247,7 @@ async def help_test_entity_available(
|
|||
|
||||
assert hass.states.get(entity_id).state != STATE_UNAVAILABLE
|
||||
|
||||
with patch_bond_device_state(side_effect=AsyncIOTimeoutError()):
|
||||
with patch_bond_device_state(side_effect=TimeoutError()):
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Test issues from supervisor issues."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError
|
||||
import os
|
||||
from typing import Any
|
||||
from unittest.mock import ANY, patch
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Tests for the homewizard component."""
|
||||
from asyncio import TimeoutError
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homewizard_energy.errors import DisabledError, HomeWizardEnergyException
|
||||
|
|
|
@ -5,7 +5,6 @@ import pytest
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.ourgroceries.config_flow import (
|
||||
AsyncIOTimeoutError,
|
||||
ClientError,
|
||||
InvalidLoginException,
|
||||
)
|
||||
|
@ -49,7 +48,7 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
|||
[
|
||||
(InvalidLoginException, "invalid_auth"),
|
||||
(ClientError, "cannot_connect"),
|
||||
(AsyncIOTimeoutError, "cannot_connect"),
|
||||
(TimeoutError, "cannot_connect"),
|
||||
(Exception, "unknown"),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -3,11 +3,7 @@ from unittest.mock import AsyncMock
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.ourgroceries import (
|
||||
AsyncIOTimeoutError,
|
||||
ClientError,
|
||||
InvalidLoginException,
|
||||
)
|
||||
from homeassistant.components.ourgroceries import ClientError, InvalidLoginException
|
||||
from homeassistant.components.ourgroceries.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -41,7 +37,7 @@ def login_with_error(exception, ourgroceries: AsyncMock):
|
|||
[
|
||||
(InvalidLoginException, ConfigEntryState.SETUP_ERROR),
|
||||
(ClientError, ConfigEntryState.SETUP_RETRY),
|
||||
(AsyncIOTimeoutError, ConfigEntryState.SETUP_RETRY),
|
||||
(TimeoutError, ConfigEntryState.SETUP_RETRY),
|
||||
],
|
||||
)
|
||||
async def test_init_failure(
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Unit tests for the OurGroceries todo platform."""
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from aiohttp import ClientError
|
||||
|
@ -257,7 +256,7 @@ async def test_version_id_optimization(
|
|||
("exception"),
|
||||
[
|
||||
(ClientError),
|
||||
(AsyncIOTimeoutError),
|
||||
(TimeoutError),
|
||||
],
|
||||
)
|
||||
async def test_coordinator_error(
|
||||
|
|
Loading…
Add table
Reference in a new issue