From fb74a230a2907c27212d18cac6b946d373bcc1a0 Mon Sep 17 00:00:00 2001 From: cdohmen Date: Sat, 28 Sep 2024 08:33:58 -0400 Subject: [PATCH] Ensure connection is closed after configflow --- custom_components/hubspace/config_flow.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/hubspace/config_flow.py b/custom_components/hubspace/config_flow.py index ead881b..8c44bc8 100644 --- a/custom_components/hubspace/config_flow.py +++ b/custom_components/hubspace/config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations +import contextlib import logging from asyncio import timeout from typing import Any, Optional @@ -9,7 +10,7 @@ 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 @@ -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") @@ -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,