From dbb093cf36abd2072ba5a2d440b466955e791abf Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 4 Aug 2023 00:56:42 +0200 Subject: [PATCH] Fix airvisual RuntimeWarning --- .../components/airvisual/config_flow.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/airvisual/config_flow.py b/homeassistant/components/airvisual/config_flow.py index 27e79f2d40bab..893726fc0223d 100644 --- a/homeassistant/components/airvisual/config_flow.py +++ b/homeassistant/components/airvisual/config_flow.py @@ -109,19 +109,21 @@ async def _async_finish_geography( "airvisual_checked_api_keys_lock", asyncio.Lock() ) - if integration_type == INTEGRATION_TYPE_GEOGRAPHY_COORDS: - coro = cloud_api.air_quality.nearest_city() - error_schema = self.geography_coords_schema - error_step = "geography_by_coords" - else: - coro = cloud_api.air_quality.city( - user_input[CONF_CITY], user_input[CONF_STATE], user_input[CONF_COUNTRY] - ) - error_schema = GEOGRAPHY_NAME_SCHEMA - error_step = "geography_by_name" - async with valid_keys_lock: if user_input[CONF_API_KEY] not in valid_keys: + if integration_type == INTEGRATION_TYPE_GEOGRAPHY_COORDS: + coro = cloud_api.air_quality.nearest_city() + error_schema = self.geography_coords_schema + error_step = "geography_by_coords" + else: + coro = cloud_api.air_quality.city( + user_input[CONF_CITY], + user_input[CONF_STATE], + user_input[CONF_COUNTRY], + ) + error_schema = GEOGRAPHY_NAME_SCHEMA + error_step = "geography_by_name" + try: await coro except (InvalidKeyError, KeyExpiredError, UnauthorizedError):