mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Auto lower case username for Schlage auth flows (#128730)
This commit is contained in:
parent
7fa359764d
commit
0b3f660626
@ -31,7 +31,7 @@ class SchlageConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
return self._show_user_form({})
|
return self._show_user_form({})
|
||||||
username = user_input[CONF_USERNAME]
|
username = user_input[CONF_USERNAME].lower()
|
||||||
password = user_input[CONF_PASSWORD]
|
password = user_input[CONF_PASSWORD]
|
||||||
user_id, errors = await self.hass.async_add_executor_job(
|
user_id, errors = await self.hass.async_add_executor_job(
|
||||||
_authenticate, username, password
|
_authenticate, username, password
|
||||||
@ -40,7 +40,13 @@ class SchlageConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
return self._show_user_form(errors)
|
return self._show_user_form(errors)
|
||||||
|
|
||||||
await self.async_set_unique_id(user_id)
|
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:
|
def _show_user_form(self, errors: dict[str, str]) -> ConfigFlowResult:
|
||||||
"""Show the user form."""
|
"""Show the user form."""
|
||||||
|
@ -15,8 +15,18 @@ from tests.common import MockConfigEntry
|
|||||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"username",
|
||||||
|
[
|
||||||
|
"test-username",
|
||||||
|
"TEST-USERNAME",
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_form(
|
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:
|
) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -28,7 +38,7 @@ async def test_form(
|
|||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
"username": "test-username",
|
"username": username,
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user