mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add missing unique_id check on blink user flows (#131209)
This commit is contained in:
parent
d6170eb071
commit
2a6e08caf9
@ -10,7 +10,7 @@ from blinkpy.auth import Auth, LoginError, TokenRefreshFailed
|
|||||||
from blinkpy.blinkpy import Blink, BlinkSetupError
|
from blinkpy.blinkpy import Blink, BlinkSetupError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_PIN, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_PIN, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -61,6 +61,8 @@ class BlinkConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
session=async_get_clientsession(self.hass),
|
session=async_get_clientsession(self.hass),
|
||||||
)
|
)
|
||||||
await self.async_set_unique_id(user_input[CONF_USERNAME])
|
await self.async_set_unique_id(user_input[CONF_USERNAME])
|
||||||
|
if self.source != SOURCE_REAUTH:
|
||||||
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await validate_input(self.auth)
|
await validate_input(self.auth)
|
||||||
|
@ -55,6 +55,35 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
# Now check for duplicates
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("homeassistant.components.blink.config_flow.Auth.startup"),
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.blink.config_flow.Auth.check_key_required",
|
||||||
|
return_value=False,
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.blink.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry,
|
||||||
|
):
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{"username": "blink@example.com", "password": "example"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result2["type"] is FlowResultType.ABORT
|
||||||
|
assert result2["reason"] == "already_configured"
|
||||||
|
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_form_2fa(hass: HomeAssistant) -> None:
|
async def test_form_2fa(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the 2fa form."""
|
"""Test we get the 2fa form."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user