Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username to Reauth flow in Honeywell #96850

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 13 additions & 12 deletions homeassistant/components/honeywell/config_flow.py
Expand Up @@ -22,7 +22,12 @@
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):
Expand All @@ -42,18 +47,12 @@ async def async_step_reauth_confirm(
) -> FlowResult:
"""Confirm re-authentication with Honeywell."""
errors: dict[str, str] = {}

assert self.entry is not None
if user_input:
assert self.entry is not None
password = user_input[CONF_PASSWORD]
data = {
CONF_USERNAME: self.entry.data[CONF_USERNAME],
CONF_PASSWORD: password,
}

try:
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:
Expand All @@ -71,15 +70,17 @@ async def async_step_reauth_confirm(
self.entry,
data={
**self.entry.data,
CONF_PASSWORD: password,
**user_input,
},
)
await self.hass.config_entries.async_reload(self.entry.entry_id)
return self.async_abort(reason="reauth_successful")

return self.async_show_form(
step_id="reauth_confirm",
data_schema=REAUTH_SCHEMA,
data_schema=self.add_suggested_values_to_schema(
REAUTH_SCHEMA, self.entry.data
),
errors=errors,
)

Expand Down
8 changes: 4 additions & 4 deletions tests/components/honeywell/test_config_flow.py
Expand Up @@ -156,14 +156,14 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_PASSWORD: "new-password"},
{CONF_USERNAME: "new-username", CONF_PASSWORD: "new-password"},
)
await hass.async_block_till_done()

assert result2["type"] == FlowResultType.ABORT
assert result2["reason"] == "reauth_successful"
assert mock_entry.data == {
CONF_USERNAME: "test-username",
CONF_USERNAME: "new-username",
CONF_PASSWORD: "new-password",
}

Expand Down Expand Up @@ -200,7 +200,7 @@ async def test_reauth_flow_auth_error(hass: HomeAssistant, client: MagicMock) ->
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_PASSWORD: "new-password"},
{CONF_USERNAME: "new-username", CONF_PASSWORD: "new-password"},
)
await hass.async_block_till_done()

Expand Down Expand Up @@ -246,7 +246,7 @@ async def test_reauth_flow_connnection_error(

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_PASSWORD: "new-password"},
{CONF_USERNAME: "new-username", CONF_PASSWORD: "new-password"},
)
await hass.async_block_till_done()

Expand Down