mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add username to Reauth flow in Honeywell (#96850)
* pre-populate username/password on reauth * Update homeassistant/components/honeywell/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use add_suggested_value_to_schema * Optimize code --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
06aeacc324
commit
3b501fd2d7
@ -22,7 +22,12 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
REAUTH_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
|
REAUTH_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_USERNAME): str,
|
||||||
|
vol.Required(CONF_PASSWORD): str,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class HoneywellConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class HoneywellConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
@ -42,18 +47,12 @@ class HoneywellConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Confirm re-authentication with Honeywell."""
|
"""Confirm re-authentication with Honeywell."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input:
|
|
||||||
assert self.entry is not None
|
assert self.entry is not None
|
||||||
password = user_input[CONF_PASSWORD]
|
if user_input:
|
||||||
data = {
|
|
||||||
CONF_USERNAME: self.entry.data[CONF_USERNAME],
|
|
||||||
CONF_PASSWORD: password,
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.is_valid(
|
await self.is_valid(
|
||||||
username=data[CONF_USERNAME], password=data[CONF_PASSWORD]
|
username=user_input[CONF_USERNAME],
|
||||||
|
password=user_input[CONF_PASSWORD],
|
||||||
)
|
)
|
||||||
|
|
||||||
except aiosomecomfort.AuthError:
|
except aiosomecomfort.AuthError:
|
||||||
@ -71,7 +70,7 @@ class HoneywellConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self.entry,
|
self.entry,
|
||||||
data={
|
data={
|
||||||
**self.entry.data,
|
**self.entry.data,
|
||||||
CONF_PASSWORD: password,
|
**user_input,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_reload(self.entry.entry_id)
|
await self.hass.config_entries.async_reload(self.entry.entry_id)
|
||||||
@ -79,7 +78,9 @@ class HoneywellConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
data_schema=REAUTH_SCHEMA,
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
|
REAUTH_SCHEMA, self.entry.data
|
||||||
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -156,14 +156,14 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
|
|||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_PASSWORD: "new-password"},
|
{CONF_USERNAME: "new-username", CONF_PASSWORD: "new-password"},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] == FlowResultType.ABORT
|
assert result2["type"] == FlowResultType.ABORT
|
||||||
assert result2["reason"] == "reauth_successful"
|
assert result2["reason"] == "reauth_successful"
|
||||||
assert mock_entry.data == {
|
assert mock_entry.data == {
|
||||||
CONF_USERNAME: "test-username",
|
CONF_USERNAME: "new-username",
|
||||||
CONF_PASSWORD: "new-password",
|
CONF_PASSWORD: "new-password",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ async def test_reauth_flow_auth_error(hass: HomeAssistant, client: MagicMock) ->
|
|||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_PASSWORD: "new-password"},
|
{CONF_USERNAME: "new-username", CONF_PASSWORD: "new-password"},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ async def test_reauth_flow_connnection_error(
|
|||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_PASSWORD: "new-password"},
|
{CONF_USERNAME: "new-username", CONF_PASSWORD: "new-password"},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user