From 1a0c3a49b934c624e8704f7eaa21f1263aef0904 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:27:04 +0200 Subject: [PATCH] Use async_update_reload_and_abort in awair (#128345) --- homeassistant/components/awair/config_flow.py | 7 +++--- tests/components/awair/test_config_flow.py | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/awair/config_flow.py b/homeassistant/components/awair/config_flow.py index 8b40eacbafca42..88985b0db10d54 100644 --- a/homeassistant/components/awair/config_flow.py +++ b/homeassistant/components/awair/config_flow.py @@ -209,10 +209,9 @@ async def async_step_reauth_confirm( _, error = await self._check_cloud_connection(access_token) if error is None: - entry = await self.async_set_unique_id(self.unique_id) - assert entry - self.hass.config_entries.async_update_entry(entry, data=user_input) - return self.async_abort(reason="reauth_successful") + return self.async_update_reload_and_abort( + self._get_reauth_entry(), data_updates=user_input + ) if error != "invalid_access_token": return self.async_abort(reason=error) diff --git a/tests/components/awair/test_config_flow.py b/tests/components/awair/test_config_flow.py index ac17cf414489fd..b27f20e83f3e2a 100644 --- a/tests/components/awair/test_config_flow.py +++ b/tests/components/awair/test_config_flow.py @@ -144,27 +144,32 @@ async def test_reauth(hass: HomeAssistant, user, cloud_devices) -> None: with patch("python_awair.AwairClient.query", side_effect=AuthError()): result = await hass.config_entries.flow.async_configure( result["flow_id"], - user_input=CLOUD_CONFIG, + user_input={CONF_ACCESS_TOKEN: "bad"}, ) - assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "reauth_confirm" - assert result["errors"] == {CONF_ACCESS_TOKEN: "invalid_access_token"} + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "reauth_confirm" + assert result["errors"] == {CONF_ACCESS_TOKEN: "invalid_access_token"} with ( patch( "python_awair.AwairClient.query", side_effect=[user, cloud_devices], ), - patch("homeassistant.components.awair.async_setup_entry", return_value=True), + patch( + "homeassistant.components.awair.async_setup_entry", return_value=True + ) as mock_setup_entry, ): result = await hass.config_entries.flow.async_configure( result["flow_id"], - user_input=CLOUD_CONFIG, + user_input={CONF_ACCESS_TOKEN: "good"}, ) + await hass.async_block_till_done() - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "reauth_successful" + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "reauth_successful" + mock_setup_entry.assert_called_once() + assert dict(mock_config.data) == {CONF_ACCESS_TOKEN: "good"} async def test_reauth_error(hass: HomeAssistant) -> None: @@ -395,10 +400,6 @@ async def test_zeroconf_discovery_update_configuration( return_value=True, ) as mock_setup_entry, patch("python_awair.AwairClient.query", side_effect=[local_devices]), - patch( - "homeassistant.components.awair.async_setup_entry", - return_value=True, - ), ): result = await hass.config_entries.flow.async_init( DOMAIN,