Skip to content

Commit

Permalink
Use async_update_reload_and_abort in awair (home-assistant#128345)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 14, 2024
1 parent c4e2e9c commit 1a0c3a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
7 changes: 3 additions & 4 deletions homeassistant/components/awair/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 13 additions & 12 deletions tests/components/awair/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1a0c3a4

Please sign in to comment.