mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Ensure Schlage config entry uniqueness (#131732)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
2f644eb61c
commit
92520fe365
@ -40,6 +40,7 @@ class SchlageConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self._show_user_form(errors)
|
||||
|
||||
await self.async_set_unique_id(user_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=username,
|
||||
data={
|
||||
|
@ -12,6 +12,8 @@ from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from . import MockSchlageConfigEntry
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
||||
@ -54,6 +56,32 @@ async def test_form(
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_requires_unique_id(
|
||||
hass: HomeAssistant,
|
||||
mock_added_config_entry: MockConfigEntry,
|
||||
mock_pyschlage_auth: Mock,
|
||||
) -> None:
|
||||
"""Test entries have unique ids."""
|
||||
init_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert init_result["type"] is FlowResultType.FORM
|
||||
assert init_result["errors"] == {}
|
||||
|
||||
create_result = await hass.config_entries.flow.async_configure(
|
||||
init_result["flow_id"],
|
||||
{
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_pyschlage_auth.authenticate.assert_called_once_with()
|
||||
assert create_result["type"] is FlowResultType.ABORT
|
||||
assert create_result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_form_invalid_auth(
|
||||
hass: HomeAssistant, mock_pyschlage_auth: Mock
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user