From 98ae7e106ca8e9fd12fe3b653e128ffbee8033c5 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Tue, 15 Feb 2022 12:46:52 -0800 Subject: [PATCH] Always create a new session in ConfigFlow in Overkiz integration (#66602) --- .../components/overkiz/config_flow.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/overkiz/config_flow.py b/homeassistant/components/overkiz/config_flow.py index 2f8dcc18921..f788d12747d 100644 --- a/homeassistant/components/overkiz/config_flow.py +++ b/homeassistant/components/overkiz/config_flow.py @@ -19,7 +19,7 @@ from homeassistant.components import dhcp, zeroconf from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.aiohttp_client import async_create_clientsession from .const import CONF_HUB, DEFAULT_HUB, DOMAIN, LOGGER @@ -46,18 +46,17 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): username = user_input[CONF_USERNAME] password = user_input[CONF_PASSWORD] server = SUPPORTED_SERVERS[user_input[CONF_HUB]] - session = async_get_clientsession(self.hass) + session = async_create_clientsession(self.hass) - client = OverkizClient( + async with OverkizClient( username=username, password=password, server=server, session=session - ) + ) as client: + await client.login() - await client.login() - - # Set first gateway id as unique id - if gateways := await client.get_gateways(): - gateway_id = gateways[0].id - await self.async_set_unique_id(gateway_id) + # Set first gateway id as unique id + if gateways := await client.get_gateways(): + gateway_id = gateways[0].id + await self.async_set_unique_id(gateway_id) async def async_step_user( self, user_input: dict[str, Any] | None = None