Auto lower case username for Schlage auth flows (#128730)

This commit is contained in:
Franck Nijhof 2024-10-20 12:48:18 +02:00 committed by GitHub
parent 7fa359764d
commit 0b3f660626
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -31,7 +31,7 @@ class SchlageConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle the initial step."""
if user_input is None:
return self._show_user_form({})
username = user_input[CONF_USERNAME]
username = user_input[CONF_USERNAME].lower()
password = user_input[CONF_PASSWORD]
user_id, errors = await self.hass.async_add_executor_job(
_authenticate, username, password
@ -40,7 +40,13 @@ class SchlageConfigFlow(ConfigFlow, domain=DOMAIN):
return self._show_user_form(errors)
await self.async_set_unique_id(user_id)
return self.async_create_entry(title=username, data=user_input)
return self.async_create_entry(
title=username,
data={
CONF_USERNAME: username,
CONF_PASSWORD: password,
},
)
def _show_user_form(self, errors: dict[str, str]) -> ConfigFlowResult:
"""Show the user form."""

View File

@ -15,8 +15,18 @@ from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.mark.parametrize(
"username",
[
"test-username",
"TEST-USERNAME",
],
)
async def test_form(
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_pyschlage_auth: Mock
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
mock_pyschlage_auth: Mock,
username: str,
) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
@ -28,7 +38,7 @@ async def test_form(
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"username": username,
"password": "test-password",
},
)