Skip to content

Commit

Permalink
Use builtin TimeoutError [e-i] (#109679)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Feb 5, 2024
1 parent c829331 commit 7a89e58
Show file tree
Hide file tree
Showing 69 changed files with 88 additions and 133 deletions.
3 changes: 1 addition & 2 deletions homeassistant/components/eliqonline/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Monitors home energy use for the ELIQ Online service."""
from __future__ import annotations

import asyncio
from datetime import timedelta
import logging

Expand Down Expand Up @@ -83,5 +82,5 @@ async def async_update(self) -> None:
_LOGGER.debug("Updated power from server %d W", self.native_value)
except KeyError:
_LOGGER.warning("Invalid response from ELIQ Online API")
except (OSError, asyncio.TimeoutError) as error:
except (OSError, TimeoutError) as error:
_LOGGER.warning("Could not connect to the ELIQ Online API: %s", error)
4 changes: 2 additions & 2 deletions homeassistant/components/elkm1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _keypad_changed(keypad: Element, changeset: dict[str, Any]) -> None:
try:
if not await async_wait_for_elk_to_sync(elk, LOGIN_TIMEOUT, SYNC_TIMEOUT):
return False
except asyncio.TimeoutError as exc:
except TimeoutError as exc:
raise ConfigEntryNotReady(f"Timed out connecting to {conf[CONF_HOST]}") from exc

elk_temp_unit = elk.panel.temperature_units
Expand Down Expand Up @@ -389,7 +389,7 @@ def sync_complete() -> None:
try:
async with asyncio.timeout(timeout):
await event.wait()
except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.debug("Timed out waiting for %s event", name)
elk.disconnect()
raise
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/elkm1/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Config flow for Elk-M1 Control integration."""
from __future__ import annotations

import asyncio
import logging
from typing import Any

Expand Down Expand Up @@ -244,7 +243,7 @@ async def _async_create_or_error(

try:
info = await validate_input(user_input, self.unique_id)
except asyncio.TimeoutError:
except TimeoutError:
return {"base": "cannot_connect"}, None
except InvalidAuth:
return {CONF_PASSWORD: "invalid_auth"}, None
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/emulated_hue/hue_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def _async_event_changed(event: EventType[EventStateChangedData]) -> None:
try:
async with asyncio.timeout(STATE_CHANGE_WAIT_TIMEOUT):
await ev.wait()
except asyncio.TimeoutError:
except TimeoutError:
pass
finally:
unsub()
2 changes: 1 addition & 1 deletion homeassistant/components/escea/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def dispatch_discovered(_):

discovery_service = await async_start_discovery_service(hass)

with suppress(asyncio.TimeoutError):
with suppress(TimeoutError):
async with asyncio.timeout(TIMEOUT_DISCOVERY):
await controller_ready.wait()

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/evil_genius_labs/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def async_step_user(

try:
info = await validate_input(self.hass, user_input)
except asyncio.TimeoutError:
except TimeoutError:
errors["base"] = "timeout"
except CannotConnect:
errors["base"] = "cannot_connect"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/flick_electric/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def _validate_input(self, user_input):
try:
async with asyncio.timeout(60):
token = await auth.async_get_access_token()
except asyncio.TimeoutError as err:
except TimeoutError as err:
raise CannotConnect() from err
except AuthException as err:
raise InvalidAuth() from err
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/flock/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ async def async_send_message(self, message, **kwargs):
response.status,
result,
)
except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.error("Timeout accessing Flock at %s", self._url)
3 changes: 1 addition & 2 deletions homeassistant/components/flux_led/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Constants of the FluxLed/MagicHome Integration."""

import asyncio
import socket
from typing import Final

Expand Down Expand Up @@ -38,7 +37,7 @@
FLUX_LED_DISCOVERY: Final = "flux_led_discovery"

FLUX_LED_EXCEPTIONS: Final = (
asyncio.TimeoutError,
TimeoutError,
socket.error,
RuntimeError,
BrokenPipeError,
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/foobot/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for the Foobot indoor air quality monitor."""
from __future__ import annotations

import asyncio
from datetime import timedelta
import logging
from typing import Any
Expand Down Expand Up @@ -118,7 +117,7 @@ async def async_setup_platform(
)
except (
aiohttp.client_exceptions.ClientConnectorError,
asyncio.TimeoutError,
TimeoutError,
FoobotClient.TooManyRequests,
FoobotClient.InternalError,
) as err:
Expand Down Expand Up @@ -175,7 +174,7 @@ async def async_update(self) -> bool:
)
except (
aiohttp.client_exceptions.ClientConnectorError,
asyncio.TimeoutError,
TimeoutError,
self._client.TooManyRequests,
self._client.InternalError,
):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/forked_daapd/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ async def _pause_and_wait_for_callback(self):
try:
async with asyncio.timeout(CALLBACK_TIMEOUT):
await self._paused_event.wait() # wait for paused
except asyncio.TimeoutError:
except TimeoutError:
self._pause_requested = False
self._paused_event.clear()

Expand Down Expand Up @@ -764,7 +764,7 @@ async def _async_announce(self, media_id: str) -> None:
async with asyncio.timeout(TTS_TIMEOUT):
await self._tts_playing_event.wait()
# we have started TTS, now wait for completion
except asyncio.TimeoutError:
except TimeoutError:
self._tts_requested = False
_LOGGER.warning("TTS request timed out")
await asyncio.sleep(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/freedns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def _update_freedns(hass, session, url, auth_token):
except aiohttp.ClientError:
_LOGGER.warning("Can't connect to FreeDNS API")

except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.warning("Timeout from FreeDNS API at %s", url)

return False
2 changes: 1 addition & 1 deletion homeassistant/components/fully_kiosk/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def _create_entry(
except (
ClientConnectorError,
FullyKioskError,
asyncio.TimeoutError,
TimeoutError,
) as error:
LOGGER.debug(error.args, exc_info=True)
errors["base"] = "cannot_connect"
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/gardena_bluetooth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The Gardena Bluetooth integration."""
from __future__ import annotations

import asyncio
import logging

from bleak.backends.device import BLEDevice
Expand Down Expand Up @@ -60,7 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
uuids = await client.get_all_characteristics_uuid()
await client.update_timestamp(dt_util.now())
except (asyncio.TimeoutError, CommunicationFailure, DeviceUnavailable) as exception:
except (TimeoutError, CommunicationFailure, DeviceUnavailable) as exception:
await client.disconnect()
raise ConfigEntryNotReady(
f"Unable to connect to device {address} due to {exception}"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/gios/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def async_step_user(
title=gios.station_name,
data=user_input,
)
except (ApiError, ClientConnectorError, asyncio.TimeoutError):
except (ApiError, ClientConnectorError, TimeoutError):
errors["base"] = "cannot_connect"
except NoStationError:
errors[CONF_STATION_ID] = "wrong_station_id"
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/google_assistant/http.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for Google Actions Smart Home Control."""
from __future__ import annotations

import asyncio
from datetime import timedelta
from http import HTTPStatus
import logging
Expand Down Expand Up @@ -216,7 +215,7 @@ async def _call():
except ClientResponseError as error:
_LOGGER.error("Request for %s failed: %d", url, error.status)
return error.status
except (asyncio.TimeoutError, ClientError):
except (TimeoutError, ClientError):
_LOGGER.error("Could not contact %s", url)
return HTTPStatus.INTERNAL_SERVER_ERROR

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_assistant/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async def handle_devices_execute(
for entity_id, result in zip(executions, execute_results):
if result is not None:
results[entity_id] = result
except asyncio.TimeoutError:
except TimeoutError:
pass

final_results = list(results.values())
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_cloud/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def async_get_tts_audio(self, message, language, options):
)
return _encoding, response.audio_content

except asyncio.TimeoutError as ex:
except TimeoutError as ex:
_LOGGER.error("Timeout for Google Cloud TTS call: %s", ex)
except Exception as ex: # pylint: disable=broad-except
_LOGGER.exception("Error occurred during Google Cloud TTS call: %s", ex)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_domains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def _update_google_domains(hass, session, domain, user, password, timeout)
except aiohttp.ClientError:
_LOGGER.warning("Can't connect to Google Domains API")

except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.warning("Timeout from Google Domains API for domain: %s", domain)

return False
2 changes: 1 addition & 1 deletion homeassistant/components/govee_light_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async with asyncio.timeout(delay=5):
while not coordinator.devices:
await asyncio.sleep(delay=1)
except asyncio.TimeoutError as ex:
except TimeoutError as ex:
raise ConfigEntryNotReady from ex

hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/govee_light_local/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def _async_has_devices(hass: HomeAssistant) -> bool:
async with asyncio.timeout(delay=5):
while not controller.devices:
await asyncio.sleep(delay=1)
except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.debug("No devices found")

devices_count = len(controller.devices)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/harmony/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Harmony data object which contains the Harmony Client."""
from __future__ import annotations

import asyncio
from collections.abc import Iterable
import logging

Expand Down Expand Up @@ -121,7 +120,7 @@ async def connect(self) -> None:
connected = False
try:
connected = await self._client.connect()
except (asyncio.TimeoutError, aioexc.TimeOut) as err:
except (TimeoutError, aioexc.TimeOut) as err:
await self._client.close()
raise ConfigEntryNotReady(
f"{self._name}: Connection timed-out to {self._address}:8088"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ async def send_command(

return await request.json(encoding="utf-8")

except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.error("Timeout on %s request", command)

except aiohttp.ClientError as err:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/hassio/http.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""HTTP Support for Hass.io."""
from __future__ import annotations

import asyncio
from http import HTTPStatus
import logging
import os
Expand Down Expand Up @@ -193,7 +192,7 @@ async def _handle(self, request: web.Request, path: str) -> web.StreamResponse:
except aiohttp.ClientError as err:
_LOGGER.error("Client error on api %s request %s", path, err)

except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.error("Client timeout error on API request %s", path)

raise HTTPBadGateway()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hlk_sw16/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def validate_input(hass: HomeAssistant, user_input):
"""Validate the user input allows us to connect."""
try:
client = await connect_client(hass, user_input)
except asyncio.TimeoutError as err:
except TimeoutError as err:
raise CannotConnect from err

try:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/homeassistant_alerts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The Home Assistant alerts integration."""
from __future__ import annotations

import asyncio
import dataclasses
from datetime import timedelta
import logging
Expand Down Expand Up @@ -53,7 +52,7 @@ async def async_update_alerts() -> None:
f"https://alerts.home-assistant.io/alerts/{alert.alert_id}.json",
timeout=aiohttp.ClientTimeout(total=30),
)
except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.warning("Error fetching %s: timeout", alert.filename)
continue

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homekit_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
try:
await conn.async_setup()
except (
asyncio.TimeoutError,
TimeoutError,
AccessoryNotFoundError,
EncryptionError,
AccessoryDisconnectedError,
) as ex:
del hass.data[KNOWN_DEVICES][conn.unique_id]
with contextlib.suppress(asyncio.TimeoutError):
with contextlib.suppress(TimeoutError):
await conn.pairing.close()
raise ConfigEntryNotReady from ex

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/homekit_controller/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Constants for the homekit_controller component."""
import asyncio

from aiohomekit.exceptions import (
AccessoryDisconnectedError,
Expand Down Expand Up @@ -108,7 +107,7 @@
}

STARTUP_EXCEPTIONS = (
asyncio.TimeoutError,
TimeoutError,
AccessoryNotFoundError,
EncryptionError,
AccessoryDisconnectedError,
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/honeywell/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Support for Honeywell (US) Total Connect Comfort climate systems."""
import asyncio
from dataclasses import dataclass

import aiosomecomfort
Expand Down Expand Up @@ -68,7 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
aiosomecomfort.device.ConnectionError,
aiosomecomfort.device.ConnectionTimeout,
aiosomecomfort.device.SomeComfortError,
asyncio.TimeoutError,
TimeoutError,
) as ex:
raise ConfigEntryNotReady(
"Failed to initialize the Honeywell client: Connection error"
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/honeywell/climate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for Honeywell (US) Total Connect Comfort climate systems."""
from __future__ import annotations

import asyncio
import datetime
from typing import Any

Expand Down Expand Up @@ -508,7 +507,7 @@ async def _login() -> None:
AuthError,
ClientConnectionError,
AscConnectionError,
asyncio.TimeoutError,
TimeoutError,
):
self._retry += 1
self._attr_available = self._retry <= RETRY
Expand All @@ -524,7 +523,7 @@ async def _login() -> None:
await _login()
return

except (AscConnectionError, ClientConnectionError, asyncio.TimeoutError):
except (AscConnectionError, ClientConnectionError, TimeoutError):
self._retry += 1
self._attr_available = self._retry <= RETRY
return
Expand Down
Loading

0 comments on commit 7a89e58

Please sign in to comment.