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
This commit is contained in:
Simon Lamon 2025-06-08 19:47:00 +02:00 committed by GitHub
parent d33080d79e
commit 560eeac457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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