mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27: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)
|
_, error = await self._check_cloud_connection(access_token)
|
||||||
|
|
||||||
if error is None:
|
if error is None:
|
||||||
entry = await self.async_set_unique_id(self.unique_id)
|
return self.async_update_reload_and_abort(
|
||||||
assert entry
|
self._get_reauth_entry(), data_updates=user_input
|
||||||
self.hass.config_entries.async_update_entry(entry, data=user_input)
|
)
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
if error != "invalid_access_token":
|
if error != "invalid_access_token":
|
||||||
return self.async_abort(reason=error)
|
return self.async_abort(reason=error)
|
||||||
|
@ -144,27 +144,32 @@ async def test_reauth(hass: HomeAssistant, user, cloud_devices) -> None:
|
|||||||
with patch("python_awair.AwairClient.query", side_effect=AuthError()):
|
with patch("python_awair.AwairClient.query", side_effect=AuthError()):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input=CLOUD_CONFIG,
|
user_input={CONF_ACCESS_TOKEN: "bad"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["errors"] == {CONF_ACCESS_TOKEN: "invalid_access_token"}
|
assert result["errors"] == {CONF_ACCESS_TOKEN: "invalid_access_token"}
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
"python_awair.AwairClient.query",
|
"python_awair.AwairClient.query",
|
||||||
side_effect=[user, cloud_devices],
|
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 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
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["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
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:
|
async def test_reauth_error(hass: HomeAssistant) -> None:
|
||||||
@ -395,10 +400,6 @@ async def test_zeroconf_discovery_update_configuration(
|
|||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry,
|
) as mock_setup_entry,
|
||||||
patch("python_awair.AwairClient.query", side_effect=[local_devices]),
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user