Log bare exceptions in the config flow (#135584)

* Log bare exceptions in the config flow

* add more

* Fix
This commit is contained in:
Joost Lekkerkerker 2025-03-25 10:34:05 +01:00 committed by GitHub
parent 348ebe1402
commit 615afeb4d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
45 changed files with 151 additions and 59 deletions

View File

@ -102,7 +102,8 @@ class AirthingsConfigFlow(ConfigFlow, domain=DOMAIN):
device = await self._get_device_data(discovery_info)
except AirthingsDeviceUpdateError:
return self.async_abort(reason="cannot_connect")
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unknown error occurred")
return self.async_abort(reason="unknown")
name = get_name(device)
@ -160,7 +161,8 @@ class AirthingsConfigFlow(ConfigFlow, domain=DOMAIN):
device = await self._get_device_data(discovery_info)
except AirthingsDeviceUpdateError:
return self.async_abort(reason="cannot_connect")
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unknown error occurred")
return self.async_abort(reason="unknown")
name = get_name(device)
self._discovered_devices[address] = Discovery(name, discovery_info, device)

View File

@ -32,7 +32,8 @@ class AirTouch5ConfigFlow(ConfigFlow, domain=DOMAIN):
client = Airtouch5SimpleClient(user_input[CONF_HOST])
try:
await client.test_connection()
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors = {"base": "cannot_connect"}
else:
await self.async_set_unique_id(user_input[CONF_HOST])

View File

@ -2,6 +2,8 @@
from __future__ import annotations
import logging
from anova_wifi import AnovaApi, InvalidLogin
import voluptuous as vol
@ -11,8 +13,10 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class AnovaConfligFlow(ConfigFlow, domain=DOMAIN):
class AnovaConfigFlow(ConfigFlow, domain=DOMAIN):
"""Sets up a config flow for Anova."""
VERSION = 1
@ -35,7 +39,8 @@ class AnovaConfligFlow(ConfigFlow, domain=DOMAIN):
await api.authenticate()
except InvalidLogin:
errors["base"] = "invalid_auth"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(

View File

@ -60,7 +60,7 @@ class AquaCellConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except AuthenticationFailed:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:

View File

@ -44,7 +44,7 @@ class ChaconDioConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except DIOChaconInvalidAuthError:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from ssl import SSLError
from typing import Any
@ -21,6 +22,8 @@ from .const import (
DOMAIN,
)
_LOGGER = logging.getLogger(__name__)
class DelugeFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Deluge."""
@ -86,7 +89,8 @@ class DelugeFlowHandler(ConfigFlow, domain=DOMAIN):
await self.hass.async_add_executor_job(api.connect)
except (ConnectionRefusedError, TimeoutError, SSLError):
return "cannot_connect"
except Exception as ex: # noqa: BLE001
except Exception as ex:
_LOGGER.exception("Unexpected error")
if type(ex).__name__ == "BadLoginError":
return "invalid_auth"
return "unknown"

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from pydexcom import AccountError, Dexcom, SessionError
@ -12,6 +13,8 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from .const import CONF_SERVER, DOMAIN, SERVER_OUS, SERVER_US
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_USERNAME): str,
@ -43,7 +46,8 @@ class DexcomConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except AccountError:
errors["base"] = "invalid_auth"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected error")
errors["base"] = "unknown"
if "base" not in errors:

View File

@ -62,6 +62,7 @@ class EheimDigitalConfigFlow(ConfigFlow, domain=DOMAIN):
except (ClientError, TimeoutError):
return self.async_abort(reason="cannot_connect")
except Exception: # noqa: BLE001
LOGGER.exception("Unknown exception occurred")
return self.async_abort(reason="unknown")
await self.async_set_unique_id(hub.main.mac_address)
self._abort_if_unique_id_configured(updates={CONF_HOST: host})

View File

@ -1,5 +1,6 @@
"""Config flow for Enigma2."""
import logging
from typing import Any, cast
from aiohttp.client_exceptions import ClientError
@ -63,6 +64,8 @@ CONFIG_SCHEMA = vol.Schema(
}
)
_LOGGER = logging.getLogger(__name__)
async def get_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema:
"""Get the options schema."""
@ -130,7 +133,8 @@ class Enigma2ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
errors = {"base": "invalid_auth"}
except ClientError:
errors = {"base": "cannot_connect"}
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors = {"base": "unknown"}
else:
unique_id = about["info"]["ifaces"][0]["mac"] or self.unique_id

View File

@ -149,7 +149,7 @@ class FroniusConfigFlow(ConfigFlow, domain=DOMAIN):
unique_id, info = await validate_host(self.hass, user_input[CONF_HOST])
except CannotConnect:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:

View File

@ -108,8 +108,8 @@ class FrontierSiliconConfigFlow(ConfigFlow, domain=DOMAIN):
self._webfsapi_url = await AFSAPI.get_webfsapi_endpoint(device_url)
except FSConnectionError:
return self.async_abort(reason="cannot_connect")
except Exception as exception: # noqa: BLE001
_LOGGER.debug(exception)
except Exception:
_LOGGER.exception("Unexpected exception")
return self.async_abort(reason="unknown")
# try to login with default pin

View File

@ -62,7 +62,7 @@ class FGLairConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except AylaAuthError:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

View File

@ -65,8 +65,8 @@ class FytaConfigFlow(ConfigFlow, domain=DOMAIN):
return {"base": "invalid_auth"}
except FytaPasswordError:
return {"base": "invalid_auth", CONF_PASSWORD: "password_error"}
except Exception as e: # noqa: BLE001
_LOGGER.error(e)
except Exception:
_LOGGER.exception("Unexpected exception")
return {"base": "unknown"}
finally:
await fyta.client.close()

View File

@ -3,6 +3,7 @@
from __future__ import annotations
import dataclasses
import logging
import re
from typing import Any, Self
@ -27,6 +28,8 @@ from homeassistant.helpers.service_info.zeroconf import (
from .common import get_api
from .const import DEVICE_TYPE_GOGOGATE2, DEVICE_TYPE_ISMARTGATE, DOMAIN
_LOGGER = logging.getLogger(__name__)
DEVICE_NAMES = {
DEVICE_TYPE_GOGOGATE2: "Gogogate2",
DEVICE_TYPE_ISMARTGATE: "ismartgate",
@ -115,7 +118,8 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN):
else:
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "cannot_connect"
if self._ip_address and self._device_type:

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from asyncio import timeout
import logging
from typing import Any
from hko import HKO, LOCATIONS, HKOError
@ -15,6 +16,8 @@ from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig
from .const import API_RHRREAD, DEFAULT_LOCATION, DOMAIN, KEY_LOCATION
_LOGGER = logging.getLogger(__name__)
def get_loc_name(item):
"""Return an array of supported locations."""
@ -54,7 +57,8 @@ class HKOConfigFlow(ConfigFlow, domain=DOMAIN):
except HKOError:
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
await self.async_set_unique_id(

View File

@ -52,7 +52,7 @@ class HomeeConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except HomeeAuthenticationFailedException:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:

View File

@ -178,8 +178,8 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
except Timeout:
_LOGGER.warning("Connection timeout", exc_info=True)
errors[CONF_URL] = "connection_timeout"
except Exception: # noqa: BLE001
_LOGGER.warning("Unknown error connecting to device", exc_info=True)
except Exception:
_LOGGER.exception("Unknown error connecting to device")
errors[CONF_URL] = "unknown"
return conn
@ -188,8 +188,8 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
try:
conn.close()
conn.requests_session.close()
except Exception: # noqa: BLE001
_LOGGER.debug("Disconnect error", exc_info=True)
except Exception:
_LOGGER.exception("Disconnect error")
async def async_step_user(
self, user_input: dict[str, Any] | None = None

View File

@ -54,7 +54,8 @@ class HusqvarnaConfigFlowHandler(
automower_api = AutomowerSession(AsyncConfigFlowAuth(websession, token), tz)
try:
status_data = await automower_api.get_status()
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
return self.async_abort(reason="unknown")
if status_data == {}:
return self.async_abort(reason="no_mower_connected")

View File

@ -50,7 +50,7 @@ class ImgwPibFlowHandler(ConfigFlow, domain=DOMAIN):
hydrological_data = await imgwpib.get_hydrological_data()
except (ClientError, TimeoutError, ApiError):
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from incomfortclient import InvalidGateway, InvalidHeaterList
@ -31,6 +32,7 @@ from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
from .const import CONF_LEGACY_SETPOINT_STATUS, DOMAIN
from .coordinator import InComfortConfigEntry, async_connect_gateway
_LOGGER = logging.getLogger(__name__)
TITLE = "Intergas InComfort/Intouch Lan2RF gateway"
CONFIG_SCHEMA = vol.Schema(
@ -88,7 +90,8 @@ async def async_try_connect_gateway(
return {"base": "no_heaters"}
except TimeoutError:
return {"base": "timeout_error"}
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
return {"base": "unknown"}
return None

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from pylast import LastFMNetwork, PyLastError, User, WSError
@ -32,6 +33,8 @@ CONFIG_SCHEMA: vol.Schema = vol.Schema(
}
)
_LOGGER = logging.getLogger(__name__)
def get_lastfm_user(api_key: str, username: str) -> tuple[User, dict[str, str]]:
"""Get and validate lastFM User."""
@ -49,7 +52,8 @@ def get_lastfm_user(api_key: str, username: str) -> tuple[User, dict[str, str]]:
errors["base"] = "invalid_auth"
else:
errors["base"] = "unknown"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
return user, errors

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from meater import AuthenticationError, MeaterApi, ServiceUnavailableError
@ -14,6 +15,8 @@ from homeassistant.helpers import aiohttp_client
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
REAUTH_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
USER_SCHEMA = vol.Schema(
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
@ -84,7 +87,8 @@ class MeaterConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_auth"
except ServiceUnavailableError:
errors["base"] = "service_unavailable_error"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown_auth_error"
else:
data = {"username": username, "password": password}

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from motionblinds import MotionDiscovery, MotionGateway
@ -28,6 +29,8 @@ from .const import (
)
from .gateway import ConnectMotionGateway
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema(
{
vol.Optional(CONF_HOST): str,
@ -93,7 +96,8 @@ class MotionBlindsFlowHandler(ConfigFlow, domain=DOMAIN):
try:
# key not needed for GetDeviceList request
await self.hass.async_add_executor_job(gateway.GetDeviceList)
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Failed to connect to Motion Gateway")
return self.async_abort(reason="not_motionblinds")
if not gateway.available:

View File

@ -1,5 +1,6 @@
"""Config flow for Mullvad VPN integration."""
import logging
from typing import Any
from mullvad_api import MullvadAPI, MullvadAPIError
@ -8,6 +9,8 @@ from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class MullvadConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Mullvad VPN."""
@ -24,7 +27,8 @@ class MullvadConfigFlow(ConfigFlow, domain=DOMAIN):
await self.hass.async_add_executor_job(MullvadAPI)
except MullvadAPIError:
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(title="Mullvad VPN", data=user_input)

View File

@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
import logging
from typing import Any
import aiohttp
@ -16,6 +17,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
STEP_USER_DATA_SCHEMA = vol.Schema({vol.Required("host"): str})
@ -60,7 +63,8 @@ class MuteSyncConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(

View File

@ -103,7 +103,7 @@ class NASwebConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors["base"] = "missing_status"
except AbortFlow:
raise
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from aiohttp.client_exceptions import ClientConnectorError
@ -19,6 +20,8 @@ from .const import CONF_PROFILE_ID, DOMAIN
AUTH_SCHEMA = vol.Schema({vol.Required(CONF_API_KEY): str})
_LOGGER = logging.getLogger(__name__)
async def async_init_nextdns(hass: HomeAssistant, api_key: str) -> NextDns:
"""Check if credentials are valid."""
@ -51,7 +54,8 @@ class NextDnsFlowHandler(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_api_key"
except (ApiError, ClientConnectorError, RetryError, TimeoutError):
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return await self.async_step_profiles()
@ -111,7 +115,8 @@ class NextDnsFlowHandler(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_api_key"
except (ApiError, ClientConnectorError, RetryError, TimeoutError):
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_update_reload_and_abort(

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from nhc.controller import NHCController
@ -12,6 +13,8 @@ from homeassistant.const import CONF_HOST
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): str,
@ -25,7 +28,8 @@ async def test_connection(host: str) -> str | None:
controller = NHCController(host, 8000)
try:
await controller.connect()
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
return "cannot_connect"
return None

View File

@ -85,7 +85,8 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
raise err from None
except CannotConnect:
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
if errors:

View File

@ -1,5 +1,6 @@
"""Config flow for ProgettiHWSW Automation integration."""
import logging
from typing import TYPE_CHECKING, Any
from ProgettiHWSW.ProgettiHWSWAPI import ProgettiHWSWAPI
@ -11,6 +12,8 @@ from homeassistant.exceptions import HomeAssistantError
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
{vol.Required("host"): str, vol.Required("port", default=80): int}
)
@ -86,7 +89,8 @@ class ProgettiHWSWConfigFlow(ConfigFlow, domain=DOMAIN):
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
user_input.update(info)

View File

@ -70,8 +70,8 @@ class QnapConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except TypeError:
errors["base"] = "invalid_auth"
except Exception as error: # noqa: BLE001
_LOGGER.error(error)
except Exception:
_LOGGER.exception("Unexpected error")
errors["base"] = "unknown"
else:
unique_id = stats["system"]["serial_number"]

View File

@ -74,8 +74,8 @@ class RabbitAirConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_host"
except TimeoutConnect:
errors["base"] = "timeout_connect"
except Exception as err: # noqa: BLE001
_LOGGER.debug("Unexpected exception: %s", err)
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
user_input[CONF_MAC] = info["mac"]

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
import aiohttp
@ -16,6 +17,8 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from .const import CONF_KAMEREON_ACCOUNT_ID, CONF_LOCALE, DOMAIN
from .renault_hub import RenaultHub
_LOGGER = logging.getLogger(__name__)
USER_SCHEMA = vol.Schema(
{
vol.Required(CONF_LOCALE): vol.In(AVAILABLE_LOCALES.keys()),
@ -54,7 +57,8 @@ class RenaultFlowHandler(ConfigFlow, domain=DOMAIN):
)
except (aiohttp.ClientConnectionError, GigyaException):
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
if login_success:

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from aioskybell import Skybell, exceptions
@ -14,6 +15,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class SkybellFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Skybell."""
@ -95,6 +98,7 @@ class SkybellFlowHandler(ConfigFlow, domain=DOMAIN):
return None, "invalid_auth"
except exceptions.SkybellException:
return None, "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
return None, "unknown"
return skybell.user_id, None

View File

@ -1,5 +1,6 @@
"""Config flow for Smarty integration."""
import logging
from typing import Any
from pysmarty2 import Smarty
@ -10,6 +11,8 @@ from homeassistant.const import CONF_HOST, CONF_NAME
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class SmartyConfigFlow(ConfigFlow, domain=DOMAIN):
"""Smarty config flow."""
@ -20,7 +23,8 @@ class SmartyConfigFlow(ConfigFlow, domain=DOMAIN):
try:
if smarty.update():
return None
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
return "unknown"
else:
return "cannot_connect"

View File

@ -41,7 +41,8 @@ class SpotifyFlowHandler(
try:
current_user = await spotify.get_current_user()
except Exception: # noqa: BLE001
except Exception:
self.logger.exception("Error while connecting to Spotify")
return self.async_abort(reason="connection_error")
name = current_user.display_name

View File

@ -151,7 +151,8 @@ class SqueezeboxConfigFlow(ConfigFlow, domain=DOMAIN):
if server.http_status == HTTPStatus.UNAUTHORIZED:
return "invalid_auth"
return "cannot_connect"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unknown exception while validating connection")
return "unknown"
if "uuid" in status:

View File

@ -190,7 +190,7 @@ class SwissPublicTransportConfigFlow(ConfigFlow, domain=DOMAIN):
return "cannot_connect"
except OpendataTransportError:
return "bad_config"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unknown error")
return "unknown"
return None

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from pytrafikverket import TrafikverketFerry
@ -17,6 +18,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import CONF_FROM, CONF_TIME, CONF_TO, DOMAIN
from .util import create_unique_id
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_API_KEY): selector.TextSelector(
@ -81,7 +84,8 @@ class TVFerryConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_auth"
except NoFerryFound:
errors["base"] = "invalid_route"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "cannot_connect"
else:
return self.async_update_reload_and_abort(
@ -120,7 +124,8 @@ class TVFerryConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_auth"
except NoFerryFound:
errors["base"] = "invalid_route"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "cannot_connect"
else:
if not errors:

View File

@ -86,8 +86,8 @@ async def validate_station(
except UnknownError as error:
_LOGGER.error("Unknown error occurred during validation %s", str(error))
errors["base"] = "cannot_connect"
except Exception as error: # noqa: BLE001
_LOGGER.error("Unknown exception occurred during validation %s", str(error))
except Exception:
_LOGGER.exception("Unknown exception occurred during validation")
errors["base"] = "cannot_connect"
return (stations, errors)

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Mapping
import logging
from typing import Any
from pytrafikverket.exceptions import (
@ -25,6 +26,8 @@ from homeassistant.helpers.selector import (
from .const import CONF_STATION, DOMAIN
_LOGGER = logging.getLogger(__name__)
class TVWeatherConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Trafikverket Weatherstation integration."""
@ -56,7 +59,8 @@ class TVWeatherConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_station"
except MultipleWeatherStationsFound:
errors["base"] = "more_stations"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected error")
errors["base"] = "cannot_connect"
else:
return self.async_create_entry(
@ -102,7 +106,8 @@ class TVWeatherConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_station"
except MultipleWeatherStationsFound:
errors["base"] = "more_stations"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "cannot_connect"
else:
return self.async_update_reload_and_abort(
@ -132,7 +137,8 @@ class TVWeatherConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_station"
except MultipleWeatherStationsFound:
errors["base"] = "more_stations"
except Exception: # noqa: BLE001
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "cannot_connect"
else:
return self.async_update_reload_and_abort(

View File

@ -57,7 +57,7 @@ class TriggerCMDConfigFlow(ConfigFlow, domain=DOMAIN):
errors[CONF_TOKEN] = "invalid_token"
except TRIGGERcmdConnectionError:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:

View File

@ -108,7 +108,7 @@ class ValloxConfigFlow(ConfigFlow, domain=DOMAIN):
errors[CONF_HOST] = "invalid_host"
except ValloxApiException:
errors[CONF_HOST] = "cannot_connect"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected exception")
errors[CONF_HOST] = "unknown"
else:

View File

@ -114,8 +114,8 @@ class DomainConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception as err: # noqa: BLE001
_LOGGER.error("Unexpected exception: %s", err)
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
await self.async_set_unique_id(info[CONF_ID])

View File

@ -67,7 +67,7 @@ class WebDavConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "invalid_auth"
except MethodNotSupportedError:
errors["base"] = "invalid_method"
except Exception: # pylint: disable=broad-except
except Exception:
_LOGGER.exception("Unexpected error")
errors["base"] = "unknown"
else: