diff --git a/homeassistant/components/abode/config_flow.py b/homeassistant/components/abode/config_flow.py index d2e321f566eb..0be9749ca868 100644 --- a/homeassistant/components/abode/config_flow.py +++ b/homeassistant/components/abode/config_flow.py @@ -13,7 +13,7 @@ from jaraco.abode.helpers.errors import MFA_CODE_REQUIRED from requests.exceptions import ConnectTimeout, HTTPError 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_USERNAME from .const import CONF_POLLING, DOMAIN, LOGGER @@ -99,6 +99,12 @@ class AbodeFlowHandler(ConfigFlow, domain=DOMAIN): } existing_entry = await self.async_set_unique_id(self._username) + if self.source == SOURCE_REAUTH: + self._abort_if_unique_id_mismatch(reason="wrong_account") + return self.async_update_reload_and_abort( + self._get_reauth_entry(), data=config_data + ) + if existing_entry: return self.async_update_reload_and_abort(existing_entry, data=config_data) diff --git a/homeassistant/components/abode/strings.json b/homeassistant/components/abode/strings.json index c706a0b91aa6..39514b9e721a 100644 --- a/homeassistant/components/abode/strings.json +++ b/homeassistant/components/abode/strings.json @@ -1,7 +1,8 @@ { "config": { "abort": { - "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" + "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]", + "wrong_account": "You must authenticate with the same Abode account that was originally configured." }, "error": { "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", diff --git a/tests/components/abode/test_config_flow.py b/tests/components/abode/test_config_flow.py index 2abed387566f..7e58c74aa5c5 100644 --- a/tests/components/abode/test_config_flow.py +++ b/tests/components/abode/test_config_flow.py @@ -154,6 +154,33 @@ async def test_step_mfa(hass: HomeAssistant) -> None: } +async def test_step_reauth_with_a_different_account(hass: HomeAssistant) -> None: + """Test reauthenticating with an account other than the configured one.""" + entry = MockConfigEntry( + domain=DOMAIN, + unique_id="user@email.com", + data={CONF_USERNAME: "user@email.com", CONF_PASSWORD: "password"}, + ) + entry.add_to_hass(hass) + + result = await entry.start_reauth_flow(hass) + + with patch("homeassistant.components.abode.config_flow.Abode"): + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={ + CONF_USERNAME: "other@email.com", + CONF_PASSWORD: "password", + }, + ) + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "wrong_account" + + assert len(hass.config_entries.async_entries()) == 1 + assert entry.data[CONF_USERNAME] == "user@email.com" + + async def test_step_reauth(hass: HomeAssistant) -> None: """Test the reauth flow.""" entry = MockConfigEntry(