mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Huawei LTE connection management cleanups (#85929)
* Disconnect rather than just logout at end of config flow Neither the connection or the requests session will be reused, so there's no reason just to logout. Do all of the connection closure so we get all of huawei-lte-api's cleanups explicitly done. * Name connect functions consistently, analoguous to disconnect
This commit is contained in:
parent
685016052b
commit
e949344dd9
@ -326,7 +326,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Huawei LTE component from config entry."""
|
||||
url = entry.data[CONF_URL]
|
||||
|
||||
def get_connection() -> Connection:
|
||||
def _connect() -> Connection:
|
||||
"""Set up a connection."""
|
||||
if entry.options.get(CONF_UNAUTHENTICATED_MODE):
|
||||
_LOGGER.debug("Connecting in unauthenticated mode, reduced feature set")
|
||||
@ -341,7 +341,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return connection
|
||||
|
||||
try:
|
||||
connection = await hass.async_add_executor_job(get_connection)
|
||||
connection = await hass.async_add_executor_job(_connect)
|
||||
except LoginErrorInvalidCredentialsException as ex:
|
||||
raise ConfigEntryAuthFailed from ex
|
||||
except Timeout as ex:
|
||||
|
@ -111,7 +111,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors=errors or {},
|
||||
)
|
||||
|
||||
async def _try_connect(
|
||||
async def _connect(
|
||||
self, user_input: dict[str, Any], errors: dict[str, str]
|
||||
) -> Connection | None:
|
||||
"""Try connecting with given data."""
|
||||
@ -149,11 +149,11 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return conn
|
||||
|
||||
@staticmethod
|
||||
def _logout(conn: Connection) -> None:
|
||||
def _disconnect(conn: Connection) -> None:
|
||||
try:
|
||||
conn.user_session.user.logout() # type: ignore[union-attr]
|
||||
conn.close()
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.debug("Could not logout", exc_info=True)
|
||||
_LOGGER.debug("Disconnect error", exc_info=True)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
@ -197,7 +197,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
wlan_settings = {}
|
||||
return device_info, wlan_settings
|
||||
|
||||
conn = await self._try_connect(user_input, errors)
|
||||
conn = await self._connect(user_input, errors)
|
||||
if errors:
|
||||
return await self._async_show_user_form(
|
||||
user_input=user_input, errors=errors
|
||||
@ -207,7 +207,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
info, wlan_settings = await self.hass.async_add_executor_job(
|
||||
get_device_info, conn
|
||||
)
|
||||
await self.hass.async_add_executor_job(self._logout, conn)
|
||||
await self.hass.async_add_executor_job(self._disconnect, conn)
|
||||
|
||||
user_input.update(
|
||||
{
|
||||
@ -298,9 +298,9 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
new_data = {**entry.data, **user_input}
|
||||
errors: dict[str, str] = {}
|
||||
conn = await self._try_connect(new_data, errors)
|
||||
conn = await self._connect(new_data, errors)
|
||||
if conn:
|
||||
await self.hass.async_add_executor_job(self._logout, conn)
|
||||
await self.hass.async_add_executor_job(self._disconnect, conn)
|
||||
if errors:
|
||||
return await self._async_show_reauth_form(
|
||||
user_input=user_input, errors=errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user