diff --git a/homeassistant/components/blackbird/media_player.py b/homeassistant/components/blackbird/media_player.py index daa23553c96..61dca6550c0 100644 --- a/homeassistant/components/blackbird/media_player.py +++ b/homeassistant/components/blackbird/media_player.py @@ -2,7 +2,6 @@ from __future__ import annotations import logging -import socket from pyblackbird import get_blackbird from serial import SerialException @@ -93,7 +92,7 @@ def setup_platform( try: blackbird = get_blackbird(host, False) connection = host - except socket.timeout: + except TimeoutError: _LOGGER.error("Error connecting to the Blackbird controller") return diff --git a/homeassistant/components/deluge/__init__.py b/homeassistant/components/deluge/__init__.py index 63412242dd0..40f4d772670 100644 --- a/homeassistant/components/deluge/__init__.py +++ b/homeassistant/components/deluge/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations import logging -import socket from ssl import SSLError from deluge_client.client import DelugeRPCClient @@ -40,11 +39,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: api.web_port = entry.data[CONF_WEB_PORT] try: await hass.async_add_executor_job(api.connect) - except ( - ConnectionRefusedError, - socket.timeout, - SSLError, - ) as ex: + except (ConnectionRefusedError, TimeoutError, SSLError) as ex: raise ConfigEntryNotReady("Connection to Deluge Daemon failed") from ex except Exception as ex: # pylint:disable=broad-except if type(ex).__name__ == "BadLoginError": diff --git a/homeassistant/components/deluge/config_flow.py b/homeassistant/components/deluge/config_flow.py index 5de61350039..db2598e1f67 100644 --- a/homeassistant/components/deluge/config_flow.py +++ b/homeassistant/components/deluge/config_flow.py @@ -2,7 +2,6 @@ from __future__ import annotations from collections.abc import Mapping -import socket from ssl import SSLError from typing import Any @@ -91,11 +90,7 @@ class DelugeFlowHandler(ConfigFlow, domain=DOMAIN): ) try: await self.hass.async_add_executor_job(api.connect) - except ( - ConnectionRefusedError, - socket.timeout, - SSLError, - ): + except (ConnectionRefusedError, TimeoutError, SSLError): return "cannot_connect" except Exception as ex: # pylint:disable=broad-except if type(ex).__name__ == "BadLoginError": diff --git a/homeassistant/components/deluge/coordinator.py b/homeassistant/components/deluge/coordinator.py index 9b0d5907b1a..7a3e840ff95 100644 --- a/homeassistant/components/deluge/coordinator.py +++ b/homeassistant/components/deluge/coordinator.py @@ -2,7 +2,6 @@ from __future__ import annotations from datetime import timedelta -import socket from ssl import SSLError from typing import Any @@ -52,7 +51,7 @@ class DelugeDataUpdateCoordinator( ) except ( ConnectionRefusedError, - socket.timeout, + TimeoutError, SSLError, FailedToReconnectException, ) as ex: diff --git a/homeassistant/components/ebusd/__init__.py b/homeassistant/components/ebusd/__init__.py index ab83759bb2d..b1eb03989ea 100644 --- a/homeassistant/components/ebusd/__init__.py +++ b/homeassistant/components/ebusd/__init__.py @@ -1,6 +1,5 @@ """Support for Ebusd daemon for communication with eBUS heating systems.""" import logging -import socket import ebusdpy import voluptuous as vol @@ -80,7 +79,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: _LOGGER.debug("Ebusd integration setup completed") return True - except (socket.timeout, OSError): + except (TimeoutError, OSError): return False diff --git a/homeassistant/components/lg_soundbar/config_flow.py b/homeassistant/components/lg_soundbar/config_flow.py index d2cb1749689..fde5c20ebd7 100644 --- a/homeassistant/components/lg_soundbar/config_flow.py +++ b/homeassistant/components/lg_soundbar/config_flow.py @@ -1,7 +1,6 @@ """Config flow to configure the LG Soundbar integration.""" import logging from queue import Empty, Full, Queue -import socket import temescal import voluptuous as vol @@ -60,7 +59,7 @@ def test_connect(host, port): details["uuid"] = uuid_q.get(timeout=QUEUE_TIMEOUT) except Empty: pass - except socket.timeout as err: + except TimeoutError as err: raise ConnectionError(f"Connection timeout with server: {host}:{port}") from err except OSError as err: raise ConnectionError(f"Cannot resolve hostname: {host}") from err diff --git a/homeassistant/components/maxcube/__init__.py b/homeassistant/components/maxcube/__init__.py index f8899ea082f..41aed4be15c 100644 --- a/homeassistant/components/maxcube/__init__.py +++ b/homeassistant/components/maxcube/__init__.py @@ -1,6 +1,5 @@ """Support for the MAX! Cube LAN Gateway.""" import logging -from socket import timeout from threading import Lock import time @@ -65,7 +64,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: try: cube = MaxCube(host, port, now=now) hass.data[DATA_KEY][host] = MaxCubeHandle(cube, scan_interval) - except timeout as ex: + except TimeoutError as ex: _LOGGER.error("Unable to connect to Max!Cube gateway: %s", str(ex)) persistent_notification.create( hass, @@ -108,7 +107,7 @@ class MaxCubeHandle: try: self.cube.update() - except timeout: + except TimeoutError: _LOGGER.error("Max!Cube connection failed") return False diff --git a/homeassistant/components/maxcube/climate.py b/homeassistant/components/maxcube/climate.py index f3d302fc209..42abed48724 100644 --- a/homeassistant/components/maxcube/climate.py +++ b/homeassistant/components/maxcube/climate.py @@ -2,7 +2,6 @@ from __future__ import annotations import logging -import socket from typing import Any from maxcube.device import ( @@ -152,7 +151,7 @@ class MaxCubeClimate(ClimateEntity): with self._cubehandle.mutex: try: self._cubehandle.cube.set_temperature_mode(self._device, temp, mode) - except (socket.timeout, OSError): + except (TimeoutError, OSError): _LOGGER.error("Setting HVAC mode failed") @property diff --git a/homeassistant/components/mikrotik/hub.py b/homeassistant/components/mikrotik/hub.py index 44d60d5dcb4..044a45fb9b5 100644 --- a/homeassistant/components/mikrotik/hub.py +++ b/homeassistant/components/mikrotik/hub.py @@ -3,7 +3,6 @@ from __future__ import annotations from datetime import timedelta import logging -import socket import ssl from typing import Any @@ -227,7 +226,7 @@ class MikrotikData: except ( librouteros.exceptions.ConnectionClosed, OSError, - socket.timeout, + TimeoutError, ) as api_error: _LOGGER.error("Mikrotik %s connection error %s", self._host, api_error) # try to reconnect @@ -330,7 +329,7 @@ def get_api(entry: dict[str, Any]) -> librouteros.Api: except ( librouteros.exceptions.LibRouterosError, OSError, - socket.timeout, + TimeoutError, ) as api_error: _LOGGER.error("Mikrotik %s error: %s", entry[CONF_HOST], api_error) if "invalid user name or password" in str(api_error): diff --git a/homeassistant/components/motion_blinds/coordinator.py b/homeassistant/components/motion_blinds/coordinator.py index e8dc5494f25..57d67165320 100644 --- a/homeassistant/components/motion_blinds/coordinator.py +++ b/homeassistant/components/motion_blinds/coordinator.py @@ -2,7 +2,6 @@ import asyncio from datetime import timedelta import logging -from socket import timeout from typing import Any from motionblinds import DEVICE_TYPES_WIFI, ParseException @@ -50,7 +49,7 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator): """Fetch data from gateway.""" try: self._gateway.Update() - except (timeout, ParseException): + except (TimeoutError, ParseException): # let the error be logged and handled by the motionblinds library return {ATTR_AVAILABLE: False} @@ -65,7 +64,7 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator): blind.Update() else: blind.Update_trigger() - except (timeout, ParseException): + except (TimeoutError, ParseException): # let the error be logged and handled by the motionblinds library return {ATTR_AVAILABLE: False} diff --git a/homeassistant/components/motion_blinds/gateway.py b/homeassistant/components/motion_blinds/gateway.py index ac18840ddeb..c0ddc9b4287 100644 --- a/homeassistant/components/motion_blinds/gateway.py +++ b/homeassistant/components/motion_blinds/gateway.py @@ -50,7 +50,7 @@ class ConnectMotionGateway: try: # update device info and get the connected sub devices await self._hass.async_add_executor_job(self.update_gateway) - except socket.timeout: + except TimeoutError: _LOGGER.error( "Timeout trying to connect to Motion Gateway with host %s", host ) diff --git a/homeassistant/components/pilight/__init__.py b/homeassistant/components/pilight/__init__.py index 60568e722ef..51a15a52ec8 100644 --- a/homeassistant/components/pilight/__init__.py +++ b/homeassistant/components/pilight/__init__.py @@ -5,7 +5,6 @@ from collections.abc import Callable from datetime import timedelta import functools import logging -import socket import threading from typing import Any, ParamSpec @@ -75,7 +74,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: try: pilight_client = pilight.Client(host=host, port=port) - except (OSError, socket.timeout) as err: + except (OSError, TimeoutError) as err: _LOGGER.error("Unable to connect to %s on port %s: %s", host, port, err) return False diff --git a/homeassistant/components/pjlink/media_player.py b/homeassistant/components/pjlink/media_player.py index 4bbf1225a92..1a7ff877bb8 100644 --- a/homeassistant/components/pjlink/media_player.py +++ b/homeassistant/components/pjlink/media_player.py @@ -1,8 +1,6 @@ """Support for controlling projector via the PJLink protocol.""" from __future__ import annotations -import socket - from pypjlink import MUTE_AUDIO, Projector from pypjlink.projector import ProjectorError import voluptuous as vol @@ -116,7 +114,7 @@ class PjLinkDevice(MediaPlayerEntity): try: projector = Projector.from_address(self._host, self._port) projector.authenticate(self._password) - except (socket.timeout, OSError) as err: + except (TimeoutError, OSError) as err: self._attr_available = False raise ProjectorError(ERR_PROJECTOR_UNAVAILABLE) from err diff --git a/homeassistant/components/radiotherm/__init__.py b/homeassistant/components/radiotherm/__init__.py index 808ee56b092..86a9fe58013 100644 --- a/homeassistant/components/radiotherm/__init__.py +++ b/homeassistant/components/radiotherm/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations from collections.abc import Coroutine -from socket import timeout from typing import Any, TypeVar from urllib.error import URLError @@ -32,7 +31,7 @@ async def _async_call_or_raise_not_ready( except RadiothermTstatError as ex: msg = f"{host} was busy (invalid value returned): {ex}" raise ConfigEntryNotReady(msg) from ex - except timeout as ex: + except TimeoutError as ex: msg = f"{host} timed out waiting for a response: {ex}" raise ConfigEntryNotReady(msg) from ex except (OSError, URLError) as ex: diff --git a/homeassistant/components/radiotherm/config_flow.py b/homeassistant/components/radiotherm/config_flow.py index ca488ade461..c370cc86484 100644 --- a/homeassistant/components/radiotherm/config_flow.py +++ b/homeassistant/components/radiotherm/config_flow.py @@ -2,7 +2,6 @@ from __future__ import annotations import logging -from socket import timeout from typing import Any from urllib.error import URLError @@ -30,7 +29,7 @@ async def validate_connection(hass: HomeAssistant, host: str) -> RadioThermInitD """Validate the connection.""" try: return await async_get_init_data(hass, host) - except (timeout, RadiothermTstatError, URLError, OSError) as ex: + except (TimeoutError, RadiothermTstatError, URLError, OSError) as ex: raise CannotConnect(f"Failed to connect to {host}: {ex}") from ex diff --git a/homeassistant/components/radiotherm/coordinator.py b/homeassistant/components/radiotherm/coordinator.py index ffc6bfcc8ba..5b0161d9f22 100644 --- a/homeassistant/components/radiotherm/coordinator.py +++ b/homeassistant/components/radiotherm/coordinator.py @@ -3,7 +3,6 @@ from __future__ import annotations from datetime import timedelta import logging -from socket import timeout from urllib.error import URLError from radiotherm.validate import RadiothermTstatError @@ -39,7 +38,7 @@ class RadioThermUpdateCoordinator(DataUpdateCoordinator[RadioThermUpdate]): except RadiothermTstatError as ex: msg = f"{self._description} was busy (invalid value returned): {ex}" raise UpdateFailed(msg) from ex - except timeout as ex: + except TimeoutError as ex: msg = f"{self._description}) timed out waiting for a response: {ex}" raise UpdateFailed(msg) from ex except (OSError, URLError) as ex: