diff --git a/homeassistant/components/ring/config_flow.py b/homeassistant/components/ring/config_flow.py index b82b4f22223..74546567270 100644 --- a/homeassistant/components/ring/config_flow.py +++ b/homeassistant/components/ring/config_flow.py @@ -65,6 +65,8 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN): """Handle the initial step.""" errors: dict[str, str] = {} if user_input is not None: + await self.async_set_unique_id(user_input[CONF_USERNAME]) + self._abort_if_unique_id_configured() try: token = await validate_input(self.hass, user_input) except Require2FA: @@ -77,7 +79,6 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" else: - await self.async_set_unique_id(user_input[CONF_USERNAME]) return self.async_create_entry( title=user_input[CONF_USERNAME], data={CONF_USERNAME: user_input[CONF_USERNAME], CONF_TOKEN: token}, diff --git a/homeassistant/components/ring/strings.json b/homeassistant/components/ring/strings.json index ed0319b7a4b..6bd7d194136 100644 --- a/homeassistant/components/ring/strings.json +++ b/homeassistant/components/ring/strings.json @@ -27,7 +27,7 @@ "unknown": "[%key:common::config_flow::error::unknown%]" }, "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", + "already_configured": "[%key:common::config_flow::abort::already_configured_account%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } }, diff --git a/tests/components/ring/test_config_flow.py b/tests/components/ring/test_config_flow.py index bbaec2e37c4..d27c4878aea 100644 --- a/tests/components/ring/test_config_flow.py +++ b/tests/components/ring/test_config_flow.py @@ -220,3 +220,25 @@ async def test_reauth_error( "token": "new-foobar", } assert len(mock_setup_entry.mock_calls) == 1 + + +async def test_account_configured( + hass: HomeAssistant, + mock_setup_entry: AsyncMock, + mock_added_config_entry: Mock, +) -> None: + """Test that user cannot configure the same account twice.""" + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + assert result["type"] is FlowResultType.FORM + assert result["errors"] == {} + + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + {"username": "foo@bar.com", "password": "test-password"}, + ) + + assert result2["type"] is FlowResultType.ABORT + assert result2["reason"] == "already_configured"