mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Use async_update_reload_and_abort in awair (#128345)
This commit is contained in:
parent
c4e2e9c4f0
commit
1a0c3a49b9
@ -209,10 +209,9 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
_, 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)
|
||||
|
@ -144,7 +144,7 @@ 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
|
||||
@ -156,15 +156,20 @@ async def test_reauth(hass: HomeAssistant, user, cloud_devices) -> None:
|
||||
"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"
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user