mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use reauth_confirm in sharkiq (#124762)
This commit is contained in:
parent
14eec2e57a
commit
45eebf3285
@ -116,9 +116,15 @@ class SharkIqConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_reauth(
|
async def async_step_reauth(
|
||||||
self, user_input: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle re-auth if login is invalid."""
|
"""Handle re-auth if login is invalid."""
|
||||||
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
async def async_step_reauth_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle a flow initiated by reauthentication."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
@ -134,7 +140,7 @@ class SharkIqConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
return self.async_abort(reason=errors["base"])
|
return self.async_abort(reason=errors["base"])
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth",
|
step_id="reauth_confirm",
|
||||||
data_schema=SHARKIQ_SCHEMA,
|
data_schema=SHARKIQ_SCHEMA,
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"region": "Shark IQ uses different services in the EU. Select your region to connect to the correct service for your account."
|
"region": "Shark IQ uses different services in the EU. Select your region to connect to the correct service for your account."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"reauth": {
|
"reauth_confirm": {
|
||||||
"data": {
|
"data": {
|
||||||
"username": "[%key:common::config_flow::data::username%]",
|
"username": "[%key:common::config_flow::data::username%]",
|
||||||
"password": "[%key:common::config_flow::data::password%]",
|
"password": "[%key:common::config_flow::data::password%]",
|
||||||
|
@ -96,14 +96,18 @@ async def test_form_error(hass: HomeAssistant, exc: Exception, base_error: str)
|
|||||||
|
|
||||||
async def test_reauth_success(hass: HomeAssistant) -> None:
|
async def test_reauth_success(hass: HomeAssistant) -> None:
|
||||||
"""Test reauth flow."""
|
"""Test reauth flow."""
|
||||||
with patch("sharkiq.AylaApi.async_sign_in", return_value=True):
|
|
||||||
mock_config = MockConfigEntry(domain=DOMAIN, unique_id=UNIQUE_ID, data=CONFIG)
|
mock_config = MockConfigEntry(domain=DOMAIN, unique_id=UNIQUE_ID, data=CONFIG)
|
||||||
mock_config.add_to_hass(hass)
|
mock_config.add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_REAUTH, "unique_id": UNIQUE_ID},
|
context={"source": config_entries.SOURCE_REAUTH, "unique_id": UNIQUE_ID},
|
||||||
data=CONFIG,
|
data=mock_config.data,
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("sharkiq.AylaApi.async_sign_in", return_value=True):
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"], user_input=CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
@ -127,13 +131,16 @@ async def test_reauth(
|
|||||||
msg: str,
|
msg: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test reauth failures."""
|
"""Test reauth failures."""
|
||||||
with patch("sharkiq.AylaApi.async_sign_in", side_effect=side_effect):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_REAUTH, "unique_id": UNIQUE_ID},
|
context={"source": config_entries.SOURCE_REAUTH, "unique_id": UNIQUE_ID},
|
||||||
data=CONFIG,
|
data=CONFIG,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with patch("sharkiq.AylaApi.async_sign_in", side_effect=side_effect):
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"], user_input=CONFIG
|
||||||
|
)
|
||||||
msg_value = result[msg_field]
|
msg_value = result[msg_field]
|
||||||
if msg_field == "errors":
|
if msg_field == "errors":
|
||||||
msg_value = msg_value.get("base")
|
msg_value = msg_value.get("base")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user