mirror of
https://github.com/home-assistant/core.git
synced 2026-02-08 08:06:13 +01:00
Cleanup unnecessary brackets for except statements (i-p) (#162405)
This commit is contained in:
@@ -46,7 +46,7 @@ class AqualinkFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
pass
|
||||
except AqualinkServiceUnauthorizedException:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (AqualinkServiceException, httpx.HTTPError):
|
||||
except AqualinkServiceException, httpx.HTTPError:
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
return self.async_create_entry(title=username, data=user_input)
|
||||
|
||||
@@ -142,7 +142,7 @@ class IcloudFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
if not devices:
|
||||
raise PyiCloudNoDevicesException # noqa: TRY301
|
||||
except (PyiCloudServiceNotActivatedException, PyiCloudNoDevicesException):
|
||||
except PyiCloudServiceNotActivatedException, PyiCloudNoDevicesException:
|
||||
_LOGGER.error("No device found in the iCloud account: %s", self._username)
|
||||
self.api = None
|
||||
return self.async_abort(reason="no_device")
|
||||
|
||||
@@ -61,7 +61,7 @@ class IgloohomeBatteryEntity(IgloohomeBaseEntity, SensorEntity):
|
||||
response = await self.api.get_device_info(
|
||||
deviceId=self.api_device_info.deviceId
|
||||
)
|
||||
except (ApiException, ClientError):
|
||||
except ApiException, ClientError:
|
||||
self._attr_available = False
|
||||
else:
|
||||
self._attr_available = True
|
||||
|
||||
@@ -130,7 +130,7 @@ async def validate_input(
|
||||
# See https://github.com/bamthomas/aioimaplib/issues/91
|
||||
# This handler is added to be able to supply a better error message
|
||||
errors["base"] = "ssl_error"
|
||||
except (TimeoutError, AioImapException, ConnectionRefusedError):
|
||||
except TimeoutError, AioImapException, ConnectionRefusedError:
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
if result != "OK":
|
||||
|
||||
@@ -395,7 +395,7 @@ class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]):
|
||||
await self.imap_client.stop_wait_server_push()
|
||||
await self.imap_client.close()
|
||||
await self.imap_client.logout()
|
||||
except (AioImapException, TimeoutError):
|
||||
except AioImapException, TimeoutError:
|
||||
if log_error:
|
||||
_LOGGER.debug("Error while cleaning up imap connection")
|
||||
finally:
|
||||
@@ -534,7 +534,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
|
||||
async with asyncio.timeout(10):
|
||||
await idle
|
||||
|
||||
except (AioImapException, TimeoutError):
|
||||
except AioImapException, TimeoutError:
|
||||
_LOGGER.debug(
|
||||
"Lost %s (will attempt to reconnect after %s s)",
|
||||
self.config_entry.data[CONF_SERVER],
|
||||
|
||||
@@ -50,7 +50,7 @@ class ImgwPibFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
hydrological_details=False,
|
||||
)
|
||||
hydrological_data = await imgwpib.get_hydrological_data()
|
||||
except (ClientError, TimeoutError, ApiError):
|
||||
except ClientError, TimeoutError, ApiError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
@@ -62,7 +62,7 @@ class ImgwPibFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
imgwpib = await ImgwPib.create(client_session)
|
||||
await imgwpib.update_hydrological_stations()
|
||||
except (ClientError, TimeoutError, ApiError):
|
||||
except ClientError, TimeoutError, ApiError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
options: list[SelectOptionDict] = [
|
||||
|
||||
@@ -302,7 +302,7 @@ def _generate_event_to_json(conf: dict) -> Callable[[Event], dict[str, Any] | No
|
||||
# as string add "_str" postfix to the field key
|
||||
try:
|
||||
json[INFLUX_CONF_FIELDS][key] = float(value)
|
||||
except (ValueError, TypeError):
|
||||
except ValueError, TypeError:
|
||||
new_key = f"{key}_str"
|
||||
new_value = str(value)
|
||||
json[INFLUX_CONF_FIELDS][new_key] = new_value
|
||||
|
||||
@@ -170,7 +170,7 @@ class _Right(_IntegrationMethod):
|
||||
def _decimal_state(state: str) -> Decimal | None:
|
||||
try:
|
||||
return Decimal(state)
|
||||
except (InvalidOperation, TypeError):
|
||||
except InvalidOperation, TypeError:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ class IntelliFireConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self._dhcp_discovered_serial = await _async_poll_local_fireplace_for_serial(
|
||||
ip_address, dhcp_mode=True
|
||||
)
|
||||
except (ConnectionError, ClientConnectionError):
|
||||
except ConnectionError, ClientConnectionError:
|
||||
LOGGER.debug(
|
||||
"DHCP Discovery has determined %s is not an IntelliFire device",
|
||||
ip_address,
|
||||
|
||||
@@ -74,7 +74,7 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
info = await validate_input(self.hass, user_input)
|
||||
except IPPConnectionUpgradeRequired:
|
||||
return self._show_setup_form({"base": "connection_upgrade"})
|
||||
except (IPPConnectionError, IPPResponseError):
|
||||
except IPPConnectionError, IPPResponseError:
|
||||
_LOGGER.debug("IPP Connection/Response Error", exc_info=True)
|
||||
return self._show_setup_form({"base": "cannot_connect"})
|
||||
except IPPParseError:
|
||||
@@ -142,7 +142,7 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
info = await validate_input(self.hass, self.discovery_info)
|
||||
except IPPConnectionUpgradeRequired:
|
||||
return self.async_abort(reason="connection_upgrade")
|
||||
except (IPPConnectionError, IPPResponseError):
|
||||
except IPPConnectionError, IPPResponseError:
|
||||
_LOGGER.debug("IPP Connection/Response Error", exc_info=True)
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except IPPParseError:
|
||||
|
||||
@@ -52,7 +52,7 @@ class IronOSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
device = Pynecil(discovery_info.address)
|
||||
try:
|
||||
await device.connect()
|
||||
except (CommunicationError, BleakError, TimeoutError):
|
||||
except CommunicationError, BleakError, TimeoutError:
|
||||
_LOGGER.debug("Cannot connect:", exc_info=True)
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
@@ -87,7 +87,7 @@ class IronOSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
device = Pynecil(address)
|
||||
try:
|
||||
await device.connect()
|
||||
except (CommunicationError, BleakError, TimeoutError):
|
||||
except CommunicationError, BleakError, TimeoutError:
|
||||
_LOGGER.debug("Cannot connect:", exc_info=True)
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
|
||||
@@ -84,7 +84,7 @@ class IronOSBaseCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
|
||||
try:
|
||||
self.device_info = await self.device.get_device_info()
|
||||
|
||||
except (CommunicationError, TimeoutError):
|
||||
except CommunicationError, TimeoutError:
|
||||
self.device_info = DeviceInfoResponse()
|
||||
|
||||
self.v223_features = (
|
||||
|
||||
@@ -58,7 +58,7 @@ class IstaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
info = ista.get_account()
|
||||
except ServerError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except (LoginError, KeycloakError):
|
||||
except LoginError, KeycloakError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
@@ -119,7 +119,7 @@ class IstaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
except ServerError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except (LoginError, KeycloakError):
|
||||
except LoginError, KeycloakError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
|
||||
@@ -75,7 +75,7 @@ async def validate_host(host: str) -> KaleidescapeDeviceInfo:
|
||||
|
||||
try:
|
||||
await device.connect()
|
||||
except (KaleidescapeError, ConnectionError):
|
||||
except KaleidescapeError, ConnectionError:
|
||||
await device.disconnect()
|
||||
raise
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ class KeyboardRemote:
|
||||
):
|
||||
repeat_tasks[event.code].cancel()
|
||||
del repeat_tasks[event.code]
|
||||
except (OSError, asyncio.CancelledError):
|
||||
except OSError, asyncio.CancelledError:
|
||||
# cancel key repeat tasks
|
||||
for task in repeat_tasks.values():
|
||||
task.cancel()
|
||||
|
||||
@@ -442,7 +442,7 @@ class KNXConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
_host = user_input[CONF_HOST]
|
||||
_host_ip = await xknx_validate_ip(_host)
|
||||
ip_v4_validator(_host_ip, multicast=False)
|
||||
except (vol.Invalid, XKNXException):
|
||||
except vol.Invalid, XKNXException:
|
||||
errors[CONF_HOST] = "invalid_ip_address"
|
||||
|
||||
_local_ip = None
|
||||
@@ -450,7 +450,7 @@ class KNXConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
_local_ip = await xknx_validate_ip(_local)
|
||||
ip_v4_validator(_local_ip, multicast=False)
|
||||
except (vol.Invalid, XKNXException):
|
||||
except vol.Invalid, XKNXException:
|
||||
errors[CONF_KNX_LOCAL_IP] = "invalid_ip_address"
|
||||
|
||||
selected_tunneling_type = user_input[CONF_KNX_TUNNELING_TYPE]
|
||||
@@ -831,7 +831,7 @@ class KNXConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
_local_ip = await xknx_validate_ip(_local)
|
||||
ip_v4_validator(_local_ip, multicast=False)
|
||||
except (vol.Invalid, XKNXException):
|
||||
except vol.Invalid, XKNXException:
|
||||
errors[CONF_KNX_LOCAL_IP] = "invalid_ip_address"
|
||||
|
||||
if not errors:
|
||||
|
||||
@@ -293,7 +293,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
try:
|
||||
await self._connection.connect()
|
||||
await self._on_ws_connected()
|
||||
except (TransportError, CannotConnectError):
|
||||
except TransportError, CannotConnectError:
|
||||
if not self._connect_error:
|
||||
self._connect_error = True
|
||||
_LOGGER.warning("Unable to connect to Kodi via websocket")
|
||||
@@ -304,7 +304,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
async def _ping(self):
|
||||
try:
|
||||
await self._kodi.ping()
|
||||
except (TransportError, CannotConnectError):
|
||||
except TransportError, CannotConnectError:
|
||||
if not self._connect_error:
|
||||
self._connect_error = True
|
||||
_LOGGER.warning("Unable to ping Kodi via websocket")
|
||||
@@ -346,7 +346,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
|
||||
try:
|
||||
self._players = await self._kodi.get_players()
|
||||
except (TransportError, ProtocolError):
|
||||
except TransportError, ProtocolError:
|
||||
if not self._connection.can_subscribe:
|
||||
self._reset_state()
|
||||
return
|
||||
@@ -836,7 +836,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
image_url, _, _ = await get_media_info(
|
||||
self._kodi, media_content_id, media_content_type
|
||||
)
|
||||
except (ProtocolError, TransportError):
|
||||
except ProtocolError, TransportError:
|
||||
return (None, None)
|
||||
|
||||
if image_url:
|
||||
|
||||
@@ -62,7 +62,7 @@ class KostalPlenticoreConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
except AuthenticationException as ex:
|
||||
errors[CONF_PASSWORD] = "invalid_auth"
|
||||
_LOGGER.error("Error response: %s", ex)
|
||||
except (ClientError, TimeoutError):
|
||||
except ClientError, TimeoutError:
|
||||
errors[CONF_HOST] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
@@ -87,7 +87,7 @@ class KostalPlenticoreConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
except AuthenticationException as ex:
|
||||
errors[CONF_PASSWORD] = "invalid_auth"
|
||||
_LOGGER.error("Error response: %s", ex)
|
||||
except (ClientError, TimeoutError):
|
||||
except ClientError, TimeoutError:
|
||||
errors[CONF_HOST] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
|
||||
@@ -53,7 +53,7 @@ class PlenticoreDataFormatter:
|
||||
"""Return the given state value as rounded integer."""
|
||||
try:
|
||||
return round(float(state))
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
return state
|
||||
|
||||
@staticmethod
|
||||
@@ -68,7 +68,7 @@ class PlenticoreDataFormatter:
|
||||
int_value = round(value)
|
||||
|
||||
return str(int_value)
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
@@ -76,7 +76,7 @@ class PlenticoreDataFormatter:
|
||||
"""Return the given state value as float rounded to three decimal places."""
|
||||
try:
|
||||
return round(float(state), 3)
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
return state
|
||||
|
||||
@staticmethod
|
||||
@@ -84,7 +84,7 @@ class PlenticoreDataFormatter:
|
||||
"""Return the given state value as energy value, scaled to kWh."""
|
||||
try:
|
||||
return round(float(state) / 1000, 1)
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
return state
|
||||
|
||||
@staticmethod
|
||||
@@ -92,7 +92,7 @@ class PlenticoreDataFormatter:
|
||||
"""Return a readable string of the inverter state."""
|
||||
try:
|
||||
value = int(state)
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
return state
|
||||
|
||||
return PlenticoreDataFormatter.INVERTER_STATES.get(value)
|
||||
@@ -102,7 +102,7 @@ class PlenticoreDataFormatter:
|
||||
"""Return a readable state of the energy manager."""
|
||||
try:
|
||||
value = int(state)
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
return state
|
||||
|
||||
return PlenticoreDataFormatter.EM_STATES.get(value)
|
||||
|
||||
@@ -108,7 +108,7 @@ class LgTVDevice(MediaPlayerEntity):
|
||||
try:
|
||||
with self._client as client:
|
||||
client.send_command(command)
|
||||
except (LgNetCastError, RequestException):
|
||||
except LgNetCastError, RequestException:
|
||||
self._attr_state = MediaPlayerState.OFF
|
||||
|
||||
def update(self) -> None:
|
||||
@@ -150,7 +150,7 @@ class LgTVDevice(MediaPlayerEntity):
|
||||
source_tuples, key=lambda channel: int(channel[1])
|
||||
)
|
||||
self._source_names = [n for n, k in sorted_sources]
|
||||
except (LgNetCastError, RequestException):
|
||||
except LgNetCastError, RequestException:
|
||||
self._attr_state = MediaPlayerState.OFF
|
||||
|
||||
def __update_volume(self):
|
||||
|
||||
@@ -60,7 +60,7 @@ class ThinQMQTT:
|
||||
if self.client is not None:
|
||||
try:
|
||||
await self.client.async_disconnect()
|
||||
except (ThinQAPIException, TypeError, ValueError):
|
||||
except ThinQAPIException, TypeError, ValueError:
|
||||
_LOGGER.exception("Failed to disconnect")
|
||||
|
||||
def _get_failed_device_count(
|
||||
|
||||
@@ -51,7 +51,7 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
user_input[CONF_API_KEY] = result[1]
|
||||
except exceptions.ArrAuthenticationException:
|
||||
errors = {"base": "invalid_auth"}
|
||||
except (ClientConnectorError, exceptions.ArrConnectionException):
|
||||
except ClientConnectorError, exceptions.ArrConnectionException:
|
||||
errors = {"base": "cannot_connect"}
|
||||
except exceptions.ArrWrongAppException:
|
||||
errors = {"base": "wrong_app"}
|
||||
|
||||
@@ -51,7 +51,7 @@ async def async_setup_platform(
|
||||
async with asyncio.timeout(timeout):
|
||||
scenes_resp = await httpsession.get(url, headers=headers)
|
||||
|
||||
except (TimeoutError, aiohttp.ClientError):
|
||||
except TimeoutError, aiohttp.ClientError:
|
||||
_LOGGER.exception("Error on %s", url)
|
||||
return
|
||||
|
||||
@@ -93,5 +93,5 @@ class LifxCloudScene(Scene):
|
||||
async with asyncio.timeout(self._timeout):
|
||||
await httpsession.put(url, headers=self._headers)
|
||||
|
||||
except (TimeoutError, aiohttp.ClientError):
|
||||
except TimeoutError, aiohttp.ClientError:
|
||||
_LOGGER.exception("Error on %s", url)
|
||||
|
||||
@@ -93,7 +93,7 @@ class LinksysSmartWifiDeviceScanner(DeviceScanner):
|
||||
|
||||
_LOGGER.debug("Device %s is connected", mac)
|
||||
self.last_results[mac] = name
|
||||
except (KeyError, IndexError):
|
||||
except KeyError, IndexError:
|
||||
_LOGGER.exception("Router returned unexpected response")
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -38,7 +38,7 @@ class LookinFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
device: Device = await self._validate_device(host=host)
|
||||
except (aiohttp.ClientError, NoUsableService):
|
||||
except aiohttp.ClientError, NoUsableService:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except Exception:
|
||||
LOGGER.exception("Unexpected exception")
|
||||
@@ -63,7 +63,7 @@ class LookinFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
host = user_input[CONF_HOST]
|
||||
try:
|
||||
device = await self._validate_device(host=host)
|
||||
except (aiohttp.ClientError, NoUsableService):
|
||||
except aiohttp.ClientError, NoUsableService:
|
||||
errors[CONF_HOST] = "cannot_connect"
|
||||
except Exception:
|
||||
LOGGER.exception("Unexpected exception")
|
||||
|
||||
@@ -432,7 +432,7 @@ async def _async_migrate_default_config(
|
||||
CONF_URL_PATH: DOMAIN,
|
||||
}
|
||||
)
|
||||
except (HomeAssistantError, vol.Invalid):
|
||||
except HomeAssistantError, vol.Invalid:
|
||||
_LOGGER.exception("Failed to create dashboard entry during migration")
|
||||
return
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ def get_temperature(coordinator: MadVRCoordinator, key: str) -> float | None:
|
||||
"""Get temperature value if valid, otherwise return None."""
|
||||
try:
|
||||
temp = float(coordinator.data.get(key, 0))
|
||||
except (AttributeError, ValueError):
|
||||
except AttributeError, ValueError:
|
||||
return None
|
||||
else:
|
||||
return temp if is_valid_temperature(temp) else None
|
||||
|
||||
@@ -149,7 +149,7 @@ class MaxCubeClimate(ClimateEntity):
|
||||
with self._cubehandle.mutex:
|
||||
try:
|
||||
self._cubehandle.cube.set_temperature_mode(self._device, temp, mode)
|
||||
except (TimeoutError, OSError):
|
||||
except TimeoutError, OSError:
|
||||
_LOGGER.error("Setting HVAC mode failed")
|
||||
|
||||
@property
|
||||
|
||||
@@ -54,7 +54,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
if err.status in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
|
||||
return self.async_abort(reason="invalid_auth")
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except (TimeoutError, ClientError):
|
||||
except TimeoutError, ClientError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except AttributeError:
|
||||
# python-melcloud library bug: login() raises AttributeError on invalid
|
||||
@@ -131,7 +131,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = "invalid_auth"
|
||||
else:
|
||||
errors["base"] = "cannot_connect"
|
||||
except (TimeoutError, ClientError):
|
||||
except TimeoutError, ClientError:
|
||||
errors["base"] = "cannot_connect"
|
||||
|
||||
return acquired_token, errors
|
||||
|
||||
@@ -365,7 +365,7 @@ class MinMaxSensor(SensorEntity):
|
||||
device_classes.append(SensorDeviceClass(device_class))
|
||||
else:
|
||||
device_classes.append(None)
|
||||
except (HomeAssistantError, ValueError):
|
||||
except HomeAssistantError, ValueError:
|
||||
# If we can't get device class for any entity, don't set it
|
||||
device_classes.append(None)
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ async def async_validate_input(
|
||||
)
|
||||
except InvalidAuth:
|
||||
errors["username"] = "invalid_auth"
|
||||
except (OSError, HTTPError, Timeout):
|
||||
except OSError, HTTPError, Timeout:
|
||||
LOGGER.exception("Cannot connect to %s", user_input[CONF_MJPEG_URL])
|
||||
errors[field] = "cannot_connect"
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ def nan_validator(value: Any) -> int:
|
||||
return value
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
except TypeError, ValueError:
|
||||
pass
|
||||
try:
|
||||
return int(value, 16)
|
||||
|
||||
@@ -26,7 +26,7 @@ async def validate_input(data: dict[str, Any]) -> dict[str, str]:
|
||||
base = Alpha2Base(data[CONF_HOST])
|
||||
try:
|
||||
await base.update_data()
|
||||
except (aiohttp.client_exceptions.ClientConnectorError, TimeoutError):
|
||||
except aiohttp.client_exceptions.ClientConnectorError, TimeoutError:
|
||||
return {"error": "cannot_connect"}
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
|
||||
@@ -115,7 +115,7 @@ class MonzoSensor(MonzoBaseEntity, SensorEntity):
|
||||
|
||||
try:
|
||||
state = self.entity_description.value_fn(self.data)
|
||||
except (KeyError, ValueError):
|
||||
except KeyError, ValueError:
|
||||
return None
|
||||
|
||||
return state
|
||||
|
||||
@@ -52,7 +52,7 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
|
||||
"""Fetch data from gateway."""
|
||||
try:
|
||||
self._gateway.Update()
|
||||
except (TimeoutError, ParseException):
|
||||
except TimeoutError, ParseException:
|
||||
# let the error be logged and handled by the motionblinds library
|
||||
return {ATTR_AVAILABLE: False}
|
||||
|
||||
@@ -67,7 +67,7 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
|
||||
blind.Update()
|
||||
else:
|
||||
blind.Update_trigger()
|
||||
except (TimeoutError, ParseException):
|
||||
except TimeoutError, ParseException:
|
||||
# let the error be logged and handled by the motionblinds library
|
||||
return {ATTR_AVAILABLE: False}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ async def handle_webhook(
|
||||
|
||||
try:
|
||||
data = await request.json()
|
||||
except (json.decoder.JSONDecodeError, UnicodeDecodeError):
|
||||
except json.decoder.JSONDecodeError, UnicodeDecodeError:
|
||||
return Response(
|
||||
text="Could not decode request",
|
||||
status=HTTPStatus.BAD_REQUEST,
|
||||
|
||||
@@ -52,7 +52,7 @@ class MotionMountFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
info = {}
|
||||
try:
|
||||
info = await self._validate_input_connect(self.connection_data)
|
||||
except (ConnectionError, socket.gaierror):
|
||||
except ConnectionError, socket.gaierror:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except TimeoutError:
|
||||
return self.async_abort(reason="time_out")
|
||||
@@ -118,7 +118,7 @@ class MotionMountFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
info = await self._validate_input_connect(self.connection_data)
|
||||
except (ConnectionError, socket.gaierror):
|
||||
except ConnectionError, socket.gaierror:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except TimeoutError:
|
||||
return self.async_abort(reason="time_out")
|
||||
|
||||
@@ -69,7 +69,7 @@ class MotionMountPresets(MotionMountEntity, SelectEntity):
|
||||
return True
|
||||
try:
|
||||
await self.mm.connect()
|
||||
except (ConnectionError, TimeoutError, socket.gaierror):
|
||||
except ConnectionError, TimeoutError, socket.gaierror:
|
||||
# We're not interested in exceptions here. In case of a failed connection
|
||||
# the try/except from the caller will report it.
|
||||
# The purpose of `_ensure_connected()` is only to make sure we try to
|
||||
|
||||
@@ -214,7 +214,7 @@ class MusicAssistantConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
# Parse zeroconf properties (strings) to ServerInfoMessage
|
||||
server_info = _parse_zeroconf_server_info(discovery_info.properties)
|
||||
except (LookupError, KeyError, ValueError):
|
||||
except LookupError, KeyError, ValueError:
|
||||
return self.async_abort(reason="invalid_discovery_info")
|
||||
|
||||
if server_info.schema_version >= HASSIO_DISCOVERY_SCHEMA_VERSION:
|
||||
@@ -321,7 +321,7 @@ class MusicAssistantConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
aiohttp_session=session,
|
||||
)
|
||||
LOGGER.debug("Successfully created long-lived token")
|
||||
except (TimeoutError, CannotConnect):
|
||||
except TimeoutError, CannotConnect:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except (AuthenticationFailed, InvalidToken) as err:
|
||||
LOGGER.error("Authentication failed: %s", err)
|
||||
@@ -364,7 +364,7 @@ class MusicAssistantConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except InvalidServerVersion:
|
||||
return self.async_abort(reason="invalid_server_version")
|
||||
except (AuthenticationFailed, InvalidToken):
|
||||
except AuthenticationFailed, InvalidToken:
|
||||
errors["base"] = "auth_failed"
|
||||
except MusicAssistantClientException:
|
||||
LOGGER.exception("Unexpected exception during manual auth")
|
||||
|
||||
@@ -61,7 +61,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
nam = await async_get_nam(self.hass, self.host, {})
|
||||
except (ApiError, ClientConnectorError, TimeoutError):
|
||||
except ApiError, ClientConnectorError, TimeoutError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except CannotGetMacError:
|
||||
return self.async_abort(reason="device_unsupported")
|
||||
@@ -96,7 +96,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
nam = await async_get_nam(self.hass, self.host, user_input)
|
||||
except AuthFailedError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (ApiError, ClientConnectorError, TimeoutError):
|
||||
except ApiError, ClientConnectorError, TimeoutError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
@@ -126,7 +126,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
nam = await async_get_nam(self.hass, self.host, {})
|
||||
except (ApiError, ClientConnectorError, TimeoutError):
|
||||
except ApiError, ClientConnectorError, TimeoutError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except CannotGetMacError:
|
||||
return self.async_abort(reason="device_unsupported")
|
||||
@@ -208,7 +208,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
try:
|
||||
nam = await async_get_nam(self.hass, user_input[CONF_HOST], {})
|
||||
except (ApiError, ClientConnectorError, TimeoutError):
|
||||
except ApiError, ClientConnectorError, TimeoutError:
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
await self.async_set_unique_id(format_mac(nam.mac))
|
||||
|
||||
@@ -60,7 +60,7 @@ class NSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
await self.hass.async_add_executor_job(client.get_stations)
|
||||
except HTTPError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (RequestsConnectionError, Timeout):
|
||||
except RequestsConnectionError, Timeout:
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception validating API key")
|
||||
@@ -142,7 +142,7 @@ class NSConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
stations = await self.hass.async_add_executor_job(client.get_stations)
|
||||
except HTTPError:
|
||||
return self.async_abort(reason="invalid_auth")
|
||||
except (RequestsConnectionError, Timeout):
|
||||
except RequestsConnectionError, Timeout:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception validating API key")
|
||||
@@ -205,7 +205,7 @@ class RouteSubentryFlowHandler(ConfigSubentryFlow):
|
||||
client.get_stations
|
||||
)
|
||||
}
|
||||
except (RequestsConnectionError, Timeout, HTTPError, ValueError):
|
||||
except RequestsConnectionError, Timeout, HTTPError, ValueError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
options = [
|
||||
|
||||
@@ -139,7 +139,7 @@ class NeurioData:
|
||||
sample = self.neurio_client.get_samples_live_last(self.sensor_id)
|
||||
self._active_power = sample["consumptionPower"]
|
||||
self._active_generation = sample.get("generationPower")
|
||||
except (requests.exceptions.RequestException, ValueError, KeyError):
|
||||
except requests.exceptions.RequestException, ValueError, KeyError:
|
||||
_LOGGER.warning("Could not update current power usage")
|
||||
|
||||
def get_daily_usage(self) -> None:
|
||||
@@ -155,7 +155,7 @@ class NeurioData:
|
||||
history = self.neurio_client.get_samples_stats(
|
||||
self.sensor_id, start_time, "days", end_time
|
||||
)
|
||||
except (requests.exceptions.RequestException, ValueError, KeyError):
|
||||
except requests.exceptions.RequestException, ValueError, KeyError:
|
||||
_LOGGER.warning("Could not update daily power usage")
|
||||
return
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
await self.hass.async_add_executor_job(self._try_connect_nc, user_input)
|
||||
except NextcloudMonitorAuthorizationError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (NextcloudMonitorConnectionError, NextcloudMonitorRequestError):
|
||||
except NextcloudMonitorConnectionError, NextcloudMonitorRequestError:
|
||||
errors["base"] = "connection_error"
|
||||
else:
|
||||
return self.async_create_entry(
|
||||
@@ -93,7 +93,7 @@ class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
except NextcloudMonitorAuthorizationError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (NextcloudMonitorConnectionError, NextcloudMonitorRequestError):
|
||||
except NextcloudMonitorConnectionError, NextcloudMonitorRequestError:
|
||||
errors["base"] = "connection_error"
|
||||
else:
|
||||
return self.async_update_reload_and_abort(
|
||||
|
||||
@@ -49,7 +49,7 @@ async def async_validate_new_api_key(
|
||||
await async_init_nextdns(hass, user_input[CONF_API_KEY], profile_id)
|
||||
except InvalidApiKeyError:
|
||||
errors["base"] = "invalid_api_key"
|
||||
except (ApiError, ClientConnectorError, RetryError, TimeoutError):
|
||||
except ApiError, ClientConnectorError, RetryError, TimeoutError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except ProfileNotAvailable:
|
||||
errors["base"] = "profile_not_available"
|
||||
@@ -82,7 +82,7 @@ class NextDnsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self.nextdns = await async_init_nextdns(self.hass, self.api_key)
|
||||
except InvalidApiKeyError:
|
||||
errors["base"] = "invalid_api_key"
|
||||
except (ApiError, ClientConnectorError, RetryError, TimeoutError):
|
||||
except ApiError, ClientConnectorError, RetryError, TimeoutError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
|
||||
@@ -41,7 +41,7 @@ class NintendoConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
try:
|
||||
await self.auth.async_complete_login(user_input[CONF_API_TOKEN])
|
||||
except (ValueError, InvalidSessionTokenException, HttpException):
|
||||
except ValueError, InvalidSessionTokenException, HttpException:
|
||||
errors["base"] = "invalid_auth"
|
||||
else:
|
||||
if TYPE_CHECKING:
|
||||
@@ -90,7 +90,7 @@ class NintendoConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
try:
|
||||
await self.auth.async_complete_login(user_input[CONF_API_TOKEN])
|
||||
except (ValueError, InvalidSessionTokenException, HttpException):
|
||||
except ValueError, InvalidSessionTokenException, HttpException:
|
||||
errors["base"] = "invalid_auth"
|
||||
else:
|
||||
return self.async_update_reload_and_abort(
|
||||
|
||||
@@ -417,7 +417,7 @@ class LeafDataStore:
|
||||
except CarwingsError:
|
||||
_LOGGER.error("An error occurred getting battery status")
|
||||
return None
|
||||
except (KeyError, TypeError):
|
||||
except KeyError, TypeError:
|
||||
_LOGGER.error("An error occurred parsing response from server")
|
||||
return None
|
||||
return server_info
|
||||
|
||||
@@ -88,7 +88,7 @@ def _seconds_to_stable_timestamp(value: StateType) -> datetime | None:
|
||||
|
||||
try:
|
||||
return _seconds_to_stable_datetime(cast(int, value))
|
||||
except (TypeError, OverflowError):
|
||||
except TypeError, OverflowError:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ def setup_platform(
|
||||
|
||||
try:
|
||||
therm = Thermostat(host, port=port, username=username, password=password)
|
||||
except (ValueError, AssertionError, requests.RequestException):
|
||||
except ValueError, AssertionError, requests.RequestException:
|
||||
return
|
||||
|
||||
add_entities((ThermostatDevice(therm, name),), True)
|
||||
|
||||
@@ -112,7 +112,7 @@ class OllamaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
client = ollama.AsyncClient(host=url, verify=get_default_context())
|
||||
async with asyncio.timeout(DEFAULT_TIMEOUT):
|
||||
await client.list()
|
||||
except (TimeoutError, httpx.ConnectError):
|
||||
except TimeoutError, httpx.ConnectError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception:
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
@@ -182,7 +182,7 @@ class OllamaSubentryFlowHandler(ConfigSubentryFlow):
|
||||
downloaded_models: set[str] = {
|
||||
model_info["model"] for model_info in response.get("models", [])
|
||||
}
|
||||
except (TimeoutError, httpx.ConnectError, httpx.HTTPError):
|
||||
except TimeoutError, httpx.ConnectError, httpx.HTTPError:
|
||||
_LOGGER.exception("Failed to get models from Ollama server")
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ async def _async_stop_device(hass: HomeAssistant, device: ONVIFDevice) -> None:
|
||||
if device.capabilities.events and device.events.started:
|
||||
try:
|
||||
await device.events.async_stop()
|
||||
except (TimeoutError, ONVIFError, Fault, aiohttp.ClientError, TransportError):
|
||||
except TimeoutError, ONVIFError, Fault, aiohttp.ClientError, TransportError:
|
||||
LOGGER.warning("Error while stopping events: %s", device.name)
|
||||
await device.device.close()
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ class ONVIFDevice:
|
||||
LOGGER.debug("%s: SetSystemDateAndTime: success", self.name)
|
||||
# Some cameras don't support setting the timezone and will throw an IndexError
|
||||
# if we try to set it. If we get an error, try again without the timezone.
|
||||
except (IndexError, Fault):
|
||||
except IndexError, Fault:
|
||||
if idx == timezone_max_idx:
|
||||
raise
|
||||
else:
|
||||
@@ -303,7 +303,7 @@ class ONVIFDevice:
|
||||
# Set Date and Time ourselves if Date and Time is set manually in the camera.
|
||||
try:
|
||||
await self.async_manually_set_date_and_time()
|
||||
except (TimeoutError, aiohttp.ClientError, TransportError, IndexError, Fault):
|
||||
except TimeoutError, aiohttp.ClientError, TransportError, IndexError, Fault:
|
||||
LOGGER.warning("%s: Could not sync date/time on this camera", self.name)
|
||||
self._async_log_time_out_of_sync(cam_date_utc, system_date)
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ class OpenAlprCloudEntity(ImageProcessingAlprEntity):
|
||||
_LOGGER.error("Error %d -> %s", request.status, data.get("error"))
|
||||
return
|
||||
|
||||
except (TimeoutError, aiohttp.ClientError):
|
||||
except TimeoutError, aiohttp.ClientError:
|
||||
_LOGGER.error("Timeout for OpenALPR API")
|
||||
return
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ def catch_request_errors[_OpenhomeDeviceT: OpenhomeDevice, **_P, _R]() -> Callab
|
||||
"""Catch TimeoutError, aiohttp.ClientError, UpnpError errors."""
|
||||
try:
|
||||
return await func(self, *args, **kwargs)
|
||||
except (TimeoutError, aiohttp.ClientError, UpnpError):
|
||||
except TimeoutError, aiohttp.ClientError, UpnpError:
|
||||
_LOGGER.error("Error during call %s", func.__name__)
|
||||
return None
|
||||
|
||||
@@ -169,7 +169,7 @@ class OpenhomeDevice(MediaPlayerEntity):
|
||||
self._attr_state = MediaPlayerState.PLAYING
|
||||
|
||||
self._attr_available = True
|
||||
except (TimeoutError, aiohttp.ClientError, UpnpError):
|
||||
except TimeoutError, aiohttp.ClientError, UpnpError:
|
||||
self._attr_available = False
|
||||
|
||||
@catch_request_errors()
|
||||
|
||||
@@ -82,7 +82,7 @@ class OpenThermGwConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
await test_connection()
|
||||
except TimeoutError:
|
||||
return self._show_form({"base": "timeout_connect"})
|
||||
except (ConnectionError, SerialException):
|
||||
except ConnectionError, SerialException:
|
||||
return self._show_form({"base": "cannot_connect"})
|
||||
|
||||
return self._create_entry(gw_id, name, device)
|
||||
|
||||
@@ -39,7 +39,7 @@ class OurGroceriesConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
og = OurGroceries(user_input[CONF_USERNAME], user_input[CONF_PASSWORD])
|
||||
try:
|
||||
await og.login()
|
||||
except (TimeoutError, ClientError):
|
||||
except TimeoutError, ClientError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except InvalidLoginException:
|
||||
errors["base"] = "invalid_auth"
|
||||
|
||||
@@ -164,7 +164,7 @@ class OverkizConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = "unsupported_hardware"
|
||||
else:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (TimeoutError, ClientError):
|
||||
except TimeoutError, ClientError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except MaintenanceException:
|
||||
errors["base"] = "server_in_maintenance"
|
||||
|
||||
@@ -81,7 +81,7 @@ class P1MonitorDataUpdateCoordinator(DataUpdateCoordinator[P1MonitorData]):
|
||||
try:
|
||||
data[SERVICE_WATERMETER] = await self.p1monitor.watermeter()
|
||||
self.has_water_meter = True
|
||||
except (P1MonitorNoDataError, P1MonitorConnectionError):
|
||||
except P1MonitorNoDataError, P1MonitorConnectionError:
|
||||
LOGGER.debug("No water meter data received from P1 Monitor")
|
||||
if self.has_water_meter is None:
|
||||
self.has_water_meter = False
|
||||
|
||||
@@ -196,7 +196,7 @@ class Remote:
|
||||
"""Send a key to the TV and handle exceptions."""
|
||||
try:
|
||||
key = getattr(Keys, key.upper())
|
||||
except (AttributeError, TypeError):
|
||||
except AttributeError, TypeError:
|
||||
key = getattr(key, "value", key)
|
||||
|
||||
assert self._control is not None
|
||||
|
||||
@@ -140,7 +140,7 @@ class PermobilConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
token, ttl = await self.p_api.request_application_token()
|
||||
self.data[CONF_TOKEN] = token
|
||||
self.data[CONF_TTL] = ttl
|
||||
except (MyPermobilAPIException, MyPermobilClientException):
|
||||
except MyPermobilAPIException, MyPermobilClientException:
|
||||
# the code did not pass validation by the api client
|
||||
# or the backend returned an error when trying to validate the code
|
||||
_LOGGER.exception("Error verifying code")
|
||||
|
||||
@@ -101,7 +101,7 @@ class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
while self._notify_wanted:
|
||||
try:
|
||||
res = await self.api.notifyChange(130)
|
||||
except (ConnectionFailure, AutenticationFailure):
|
||||
except ConnectionFailure, AutenticationFailure:
|
||||
res = None
|
||||
|
||||
if res:
|
||||
|
||||
@@ -120,7 +120,7 @@ class PicnicUpdateCoordinator(DataUpdateCoordinator):
|
||||
copy.deepcopy(next_deliveries[-1]) if next_deliveries else {}
|
||||
)
|
||||
last_order = copy.deepcopy(deliveries[0]) if deliveries else {}
|
||||
except (KeyError, TypeError):
|
||||
except KeyError, TypeError:
|
||||
# A KeyError or TypeError indicate that the response contains unexpected data
|
||||
return {}, {}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ class PlaystationNetworkConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
user = await psn.get_user()
|
||||
except PSNAWPAuthenticationError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (PSNAWPNotFoundError, PSNAWPInvalidTokenError):
|
||||
except PSNAWPNotFoundError, PSNAWPInvalidTokenError:
|
||||
errors["base"] = "invalid_account"
|
||||
except PSNAWPError:
|
||||
errors["base"] = "cannot_connect"
|
||||
|
||||
@@ -245,7 +245,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
def get_plex_account(plex_server):
|
||||
try:
|
||||
return plex_server.account
|
||||
except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized):
|
||||
except plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized:
|
||||
return None
|
||||
|
||||
await hass.async_add_executor_job(get_plex_account, plex_server)
|
||||
|
||||
@@ -216,13 +216,13 @@ class PlexFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
except NoServersFound:
|
||||
_LOGGER.error("No servers linked to Plex account")
|
||||
errors["base"] = "no_servers"
|
||||
except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized):
|
||||
except plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized:
|
||||
_LOGGER.error("Invalid credentials provided, config not created")
|
||||
errors[CONF_TOKEN] = "faulty_credentials"
|
||||
except requests.exceptions.SSLError as error:
|
||||
_LOGGER.error("SSL certificate error: [%s]", error)
|
||||
errors["base"] = "ssl_error"
|
||||
except (plexapi.exceptions.NotFound, requests.exceptions.ConnectionError):
|
||||
except plexapi.exceptions.NotFound, requests.exceptions.ConnectionError:
|
||||
server_identifier = (
|
||||
server_config.get(CONF_URL) or plex_server.server_choice or "Unknown"
|
||||
)
|
||||
|
||||
@@ -114,7 +114,7 @@ class PlexServer:
|
||||
if not self._plex_account and self._use_plex_tv:
|
||||
try:
|
||||
self._plex_account = plexapi.myplex.MyPlexAccount(token=self._token)
|
||||
except (BadRequest, Unauthorized):
|
||||
except BadRequest, Unauthorized:
|
||||
self._use_plex_tv = False
|
||||
_LOGGER.error("Not authorized to access plex.tv with provided token")
|
||||
raise
|
||||
@@ -402,7 +402,7 @@ class PlexServer:
|
||||
identifier=machine_identifier,
|
||||
token=self._plex_server.createToken(),
|
||||
)
|
||||
except (NotFound, requests.exceptions.ConnectionError):
|
||||
except NotFound, requests.exceptions.ConnectionError:
|
||||
_LOGGER.error(
|
||||
"Direct client connection failed, will try again: %s (%s)",
|
||||
name,
|
||||
|
||||
@@ -53,7 +53,7 @@ class PlexUpdate(UpdateEntity):
|
||||
if (release := self._server.plex_server.checkForUpdate()) is None:
|
||||
self._attr_latest_version = self.installed_version
|
||||
return
|
||||
except (requests.exceptions.RequestException, PlexApiException):
|
||||
except requests.exceptions.RequestException, PlexApiException:
|
||||
_LOGGER.debug("Polling update sensor failed, will try again")
|
||||
return
|
||||
self._attr_latest_version = release.version
|
||||
|
||||
@@ -103,7 +103,7 @@ async def verify_connection(
|
||||
errors[CONF_BASE] = "invalid_auth"
|
||||
except InvalidSetupError:
|
||||
errors[CONF_BASE] = "invalid_setup"
|
||||
except (InvalidXMLError, ResponseError):
|
||||
except InvalidXMLError, ResponseError:
|
||||
errors[CONF_BASE] = "response_error"
|
||||
except UnsupportedDeviceError:
|
||||
errors[CONF_BASE] = "unsupported"
|
||||
|
||||
@@ -517,7 +517,7 @@ class PrometheusMetrics:
|
||||
for key, value in state.attributes.items():
|
||||
try:
|
||||
value = float(value)
|
||||
except (ValueError, TypeError):
|
||||
except ValueError, TypeError:
|
||||
continue
|
||||
|
||||
self._metric(
|
||||
|
||||
@@ -82,7 +82,7 @@ def call_api_container_vm(
|
||||
status = proxmox.nodes(node_name).qemu(vm_id).status.current.get()
|
||||
elif machine_type == TYPE_CONTAINER:
|
||||
status = proxmox.nodes(node_name).lxc(vm_id).status.current.get()
|
||||
except (ResourceException, requests.exceptions.ConnectionError):
|
||||
except ResourceException, requests.exceptions.ConnectionError:
|
||||
return None
|
||||
|
||||
return status
|
||||
|
||||
@@ -123,7 +123,7 @@ class PushBulletNotificationSensor(SensorEntity):
|
||||
else:
|
||||
self._attr_native_value = value
|
||||
self._attr_extra_state_attributes = self.pb_provider.data
|
||||
except (KeyError, TypeError):
|
||||
except KeyError, TypeError:
|
||||
pass
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self._async_abort_entries_match({CONF_URL: url})
|
||||
try:
|
||||
await validate_input(self.hass, user_input)
|
||||
except (CannotConnect, ParserError):
|
||||
except CannotConnect, ParserError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except InvalidAuth:
|
||||
errors["base"] = "invalid_auth"
|
||||
@@ -154,7 +154,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
try:
|
||||
await validate_input(self.hass, {**reauth_entry.data, **user_input})
|
||||
except (CannotConnect, ParserError):
|
||||
except CannotConnect, ParserError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except InvalidAuth:
|
||||
errors["base"] = "invalid_auth"
|
||||
@@ -190,7 +190,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
try:
|
||||
await validate_input(self.hass, user_input)
|
||||
except (CannotConnect, ParserError):
|
||||
except CannotConnect, ParserError:
|
||||
errors["base"] = "cannot_connect"
|
||||
except InvalidAuth:
|
||||
errors["base"] = "invalid_auth"
|
||||
@@ -249,7 +249,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
await validate_input(self.hass, data)
|
||||
except (CannotConnect, ParserError):
|
||||
except CannotConnect, ParserError:
|
||||
_LOGGER.debug("Cannot connect", exc_info=True)
|
||||
errors["base"] = "cannot_connect"
|
||||
except InvalidAuth:
|
||||
|
||||
Reference in New Issue
Block a user