Abort linkplay zeroconf flow before probing when UUID is already known (#176123)

This commit is contained in:
David Wu
2026-07-10 21:50:17 +02:00
committed by GitHub
parent ab4ab8386f
commit 4b29091f44
3 changed files with 67 additions and 4 deletions
@@ -36,6 +36,17 @@ class LinkPlayConfigFlow(ConfigFlow, domain=DOMAIN):
# Do not probe the device if the host is already configured
self._async_abort_entries_match({CONF_HOST: discovery_info.host})
# Do not probe the device if the UUID advertised over mDNS matches
# an existing (or ignored) entry
if uuid := discovery_info.properties.get("uuid"):
# The advertised UUID is prefixed and dashed
# (uuid:FF31F09E-5001-...), while the device API (and therefore
# the stored unique id) uses the dashless form
await self.async_set_unique_id(uuid.removeprefix("uuid:").replace("-", ""))
self._abort_if_unique_id_configured(
updates={CONF_HOST: discovery_info.host}
)
session: ClientSession = await async_get_client_session(self.hass)
bridge: LinkPlayBridge | None = None
+1 -1
View File
@@ -19,7 +19,7 @@ from tests.conftest import AiohttpClientMocker
HOST = "10.0.0.150"
HOST_REENTRY = "10.0.0.66"
UUID = "FF31F09E-5001-FBDE-0546-2DBFFF31F09E"
UUID = "FF31F09E5001FBDE05462DBFFF31F09E"
NAME = "Smart Zone 1_54B9"
+55 -3
View File
@@ -8,7 +8,7 @@ from linkplay.manufacturers import MANUFACTURER_WIIM
import pytest
from homeassistant.components.linkplay.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.config_entries import SOURCE_IGNORE, SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@@ -26,7 +26,7 @@ ZEROCONF_DISCOVERY = ZeroconfServiceInfo(
port=59152,
type="_linkplay._tcp.local.",
properties={
"uuid": f"uuid:{UUID}",
"uuid": "uuid:FF31F09E-5001-FBDE-0546-2DBFFF31F09E",
"mac": "00:2F:69:01:84:3A",
"security": "https 2.0",
"upnp": "1.0.0",
@@ -42,7 +42,7 @@ ZEROCONF_DISCOVERY_RE_ENTRY = ZeroconfServiceInfo(
port=59152,
type="_linkplay._tcp.local.",
properties={
"uuid": f"uuid:{UUID}",
"uuid": "uuid:FF31F09E-5001-FBDE-0546-2DBFFF31F09E",
"mac": "00:2F:69:01:84:3A",
"security": "https 2.0",
"upnp": "1.0.0",
@@ -134,6 +134,58 @@ async def test_zeroconf_flow(
assert result["result"].unique_id == UUID
async def test_zeroconf_flow_ignored_entry(
hass: HomeAssistant,
mock_linkplay_factory_bridge: AsyncMock,
) -> None:
"""Test Zeroconf discovery does not probe a device with an ignored entry."""
entry = MockConfigEntry(
data={},
domain=DOMAIN,
title=NAME,
unique_id=UUID,
source=SOURCE_IGNORE,
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=ZEROCONF_DISCOVERY,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
mock_linkplay_factory_bridge.assert_not_called()
async def test_zeroconf_flow_same_uuid_does_not_probe(
hass: HomeAssistant,
mock_linkplay_factory_bridge: AsyncMock,
) -> None:
"""Test Zeroconf discovery aborts before probing when the UUID matches."""
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_RE_ENTRY,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.data[CONF_HOST] == HOST_REENTRY
mock_linkplay_factory_bridge.assert_not_called()
@pytest.mark.usefixtures("mock_linkplay_factory_bridge")
async def test_zeroconf_flow_re_entry(
hass: HomeAssistant,