diff --git a/homeassistant/components/simplisafe/config_flow.py b/homeassistant/components/simplisafe/config_flow.py index 93a2e152ad8..ad9614c0546 100644 --- a/homeassistant/components/simplisafe/config_flow.py +++ b/homeassistant/components/simplisafe/config_flow.py @@ -126,7 +126,8 @@ class SimpliSafeFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): if existing_entries := [ entry for entry in self.hass.config_entries.async_entries() - if entry.unique_id in (self._username, user_id) + if entry.domain == DOMAIN + and entry.unique_id in (self._username, user_id) ]: existing_entry = existing_entries[0] self.hass.config_entries.async_update_entry( diff --git a/tests/components/simplisafe/test_config_flow.py b/tests/components/simplisafe/test_config_flow.py index 91274f8f0c5..a4ef98e0e09 100644 --- a/tests/components/simplisafe/test_config_flow.py +++ b/tests/components/simplisafe/test_config_flow.py @@ -12,6 +12,8 @@ from homeassistant.const import CONF_CODE, CONF_TOKEN, CONF_USERNAME from .common import REFRESH_TOKEN, USER_ID, USERNAME +from tests.common import MockConfigEntry + CONF_USER_ID = "user_id" @@ -57,9 +59,15 @@ async def test_options_flow(hass, config_entry): @pytest.mark.parametrize("unique_id", [USERNAME, USER_ID]) async def test_step_reauth( - hass, config, config_entry, reauth_config, setup_simplisafe, sms_config + hass, config, config_entry, reauth_config, setup_simplisafe, sms_config, unique_id ): """Test the re-auth step (testing both username and user ID as unique ID).""" + # Add a second config entry (tied to a random domain, but with the same unique ID + # that could exist in a SimpliSafe entry) to ensure that this reauth process only + # touches the SimpliSafe entry: + entry = MockConfigEntry(domain="random", unique_id=USERNAME, data={"some": "data"}) + entry.add_to_hass(hass) + result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_REAUTH}, data=config ) @@ -78,11 +86,17 @@ async def test_step_reauth( assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "reauth_successful" - assert len(hass.config_entries.async_entries()) == 1 + assert len(hass.config_entries.async_entries()) == 2 + + # Test that the SimpliSafe config flow is updated: [config_entry] = hass.config_entries.async_entries(DOMAIN) assert config_entry.unique_id == USER_ID assert config_entry.data == config + # Test that the non-SimpliSafe config flow remains the same: + [config_entry] = hass.config_entries.async_entries("random") + assert config_entry == entry + @pytest.mark.parametrize( "exc,error_string",