diff --git a/homeassistant/components/bring/config_flow.py b/homeassistant/components/bring/config_flow.py index 606c280cf8d..b8ee9d1e6ae 100644 --- a/homeassistant/components/bring/config_flow.py +++ b/homeassistant/components/bring/config_flow.py @@ -85,6 +85,7 @@ class BringConfigFlow(ConfigFlow, domain=DOMAIN): if user_input is not None: if not (errors := await self.validate_input(user_input)): + self._abort_if_unique_id_mismatch() return self.async_update_reload_and_abort( self.reauth_entry, data=user_input ) diff --git a/homeassistant/components/bring/quality_scale.yaml b/homeassistant/components/bring/quality_scale.yaml index 5d47a3577cc..922306930f2 100644 --- a/homeassistant/components/bring/quality_scale.yaml +++ b/homeassistant/components/bring/quality_scale.yaml @@ -7,9 +7,7 @@ rules: brands: done common-modules: done config-flow-test-coverage: done - config-flow: - status: todo - comment: Check uuid match in reauth + config-flow: done dependency-transparency: done docs-actions: done docs-high-level-description: todo diff --git a/homeassistant/components/bring/strings.json b/homeassistant/components/bring/strings.json index c8c12090118..7331f68a161 100644 --- a/homeassistant/components/bring/strings.json +++ b/homeassistant/components/bring/strings.json @@ -26,7 +26,8 @@ }, "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_service%]", - "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" + "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]", + "unique_id_mismatch": "The login details correspond to a different account. Please re-authenticate to the previously configured account." } }, "entity": { diff --git a/tests/components/bring/test_config_flow.py b/tests/components/bring/test_config_flow.py index 8d215a5d3ee..93e86051a75 100644 --- a/tests/components/bring/test_config_flow.py +++ b/tests/components/bring/test_config_flow.py @@ -188,3 +188,29 @@ async def test_flow_reauth_error_and_recover( assert result["reason"] == "reauth_successful" assert len(hass.config_entries.async_entries()) == 1 + + +async def test_flow_reauth_unique_id_mismatch( + hass: HomeAssistant, + bring_config_entry: MockConfigEntry, + mock_bring_client: AsyncMock, +) -> None: + """Test we abort reauth if unique id mismatch.""" + + mock_bring_client.uuid = "11111111-11111111-11111111-11111111" + + bring_config_entry.add_to_hass(hass) + + result = await bring_config_entry.start_reauth_flow(hass) + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "reauth_confirm" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + {CONF_EMAIL: "new-email", CONF_PASSWORD: "new-password"}, + ) + + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "unique_id_mismatch"