From ce3f918c2c6f5321f2401158afcb6ed5d4637f89 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 15 Nov 2021 15:30:26 -0700 Subject: [PATCH] Fix bug in AirVisual re-auth (#59685) --- homeassistant/components/airvisual/config_flow.py | 5 ++++- tests/components/airvisual/test_config_flow.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/airvisual/config_flow.py b/homeassistant/components/airvisual/config_flow.py index ebd5373f1b9..85ee4bf6ae5 100644 --- a/homeassistant/components/airvisual/config_flow.py +++ b/homeassistant/components/airvisual/config_flow.py @@ -135,6 +135,9 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): existing_entry = await self.async_set_unique_id(self._geo_id) if existing_entry: self.hass.config_entries.async_update_entry(existing_entry, data=user_input) + self.hass.async_create_task( + self.hass.config_entries.async_reload(existing_entry.entry_id) + ) return self.async_abort(reason="reauth_successful") return self.async_create_entry( @@ -231,7 +234,7 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): step_id="reauth_confirm", data_schema=API_KEY_DATA_SCHEMA ) - conf = {CONF_API_KEY: user_input[CONF_API_KEY], **self._entry_data_for_reauth} + conf = {**self._entry_data_for_reauth, CONF_API_KEY: user_input[CONF_API_KEY]} return await self._async_finish_geography( conf, self._entry_data_for_reauth[CONF_INTEGRATION_TYPE] diff --git a/tests/components/airvisual/test_config_flow.py b/tests/components/airvisual/test_config_flow.py index 6125b71e303..65534f1f16c 100644 --- a/tests/components/airvisual/test_config_flow.py +++ b/tests/components/airvisual/test_config_flow.py @@ -355,16 +355,19 @@ async def test_step_reauth(hass): assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "reauth_confirm" + new_api_key = "defgh67890" + with patch( "homeassistant.components.airvisual.async_setup_entry", return_value=True ), patch("pyairvisual.air_quality.AirQuality.nearest_city", return_value=True): result = await hass.config_entries.flow.async_configure( - result["flow_id"], user_input={CONF_API_KEY: "defgh67890"} + result["flow_id"], user_input={CONF_API_KEY: new_api_key} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "reauth_successful" assert len(hass.config_entries.async_entries()) == 1 + assert hass.config_entries.async_entries()[0].data[CONF_API_KEY] == new_api_key async def test_step_user(hass):