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