From 560eeac4571795d7232283570642a8cf5df551bd Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Sun, 8 Jun 2025 19:47:00 +0200 Subject: [PATCH] Do not probe linkplay device if another config entry already contains the host (#146305) * Do not probe if config entry already contains the host * Add unit test * Use common fixture --- .../components/linkplay/config_flow.py | 3 +++ tests/components/linkplay/test_config_flow.py | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/homeassistant/components/linkplay/config_flow.py b/homeassistant/components/linkplay/config_flow.py index 11e4aabf257..266d2fef857 100644 --- a/homeassistant/components/linkplay/config_flow.py +++ b/homeassistant/components/linkplay/config_flow.py @@ -31,6 +31,9 @@ class LinkPlayConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Handle Zeroconf discovery.""" + # Do not probe the device if the host is already configured + self._async_abort_entries_match({CONF_HOST: discovery_info.host}) + session: ClientSession = await async_get_client_session(self.hass) bridge: LinkPlayBridge | None = None diff --git a/tests/components/linkplay/test_config_flow.py b/tests/components/linkplay/test_config_flow.py index adf6aa601ae..8c0dd4af88b 100644 --- a/tests/components/linkplay/test_config_flow.py +++ b/tests/components/linkplay/test_config_flow.py @@ -220,3 +220,28 @@ async def test_user_flow_errors( CONF_HOST: HOST, } assert result["result"].unique_id == UUID + + +@pytest.mark.usefixtures("mock_linkplay_factory_bridge") +async def test_zeroconf_no_probe_existing_device( + hass: HomeAssistant, mock_linkplay_factory_bridge: AsyncMock +) -> None: + """Test we do not probe the device is the host is already configured.""" + entry = MockConfigEntry( + data={CONF_HOST: HOST}, + domain=DOMAIN, + title=NAME, + unique_id=UUID, + ) + entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_ZEROCONF}, + data=ZEROCONF_DISCOVERY, + ) + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" + assert len(mock_linkplay_factory_bridge.mock_calls) == 0