Skip to content

Commit

Permalink
Ensure connection is closed after configflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Expl0dingBanana committed Sep 28, 2024
1 parent f75ba59 commit fb74a23
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/hubspace/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from __future__ import annotations

import contextlib
import logging
from asyncio import timeout
from typing import Any, Optional

import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
from hubspace_async import HubSpaceConnection, InvalidAuth
from hubspace_async import HubSpaceConnection, InvalidAuth, InvalidResponse

from .const import DEFAULT_TIMEOUT, DOMAIN
from .const import VERSION_MAJOR as const_maj
Expand Down Expand Up @@ -51,7 +52,7 @@ async def validate_auth(
await self.conn.get_account_id()
except TimeoutError:
err_type = "cannot_connect"
except InvalidAuth:
except (InvalidAuth, InvalidResponse):
err_type = "invalid_auth"
except Exception:
_LOGGER.exception("Unexpected exception")
Expand All @@ -73,9 +74,12 @@ async def async_step_user(
await self.conn.account_id, raise_on_progress=False
)
# self._abort_if_unique_id_configured()
await self.conn.client.close()
return self.async_create_entry(title=DOMAIN, data=user_input)
else:
errors["base"] = err_type
with contextlib.suppress(Exception):
await self.conn.client.close()
return self.async_show_form(
step_id="user",
data_schema=LOGIN_SCHEMA,
Expand Down

0 comments on commit fb74a23

Please sign in to comment.