From 6e893d9162331e09895b5b9be21af057c70b9e3d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 29 Sep 2022 22:21:00 -0400 Subject: [PATCH] Store alternative domain for Zeroconf homekit discovery (#79240) --- homeassistant/components/zeroconf/__init__.py | 10 +++++++++- tests/components/zeroconf/test_init.py | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index e6c635dc308..5a2fc61f897 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -404,6 +404,7 @@ class ZeroconfDiscovery: _LOGGER.debug("Discovered new device %s %s", name, info) props: dict[str, str] = info.properties + domain = None # If we can handle it as a HomeKit discovery, we do that here. if service_type in HOMEKIT_TYPES and ( @@ -458,10 +459,17 @@ class ZeroconfDiscovery: matcher_domain = matcher["domain"] assert isinstance(matcher_domain, str) + context = { + "source": config_entries.SOURCE_ZEROCONF, + } + if domain: + # Domain of integration that offers alternative API to handle this device. + context["alternative_domain"] = domain + discovery_flow.async_create_flow( self.hass, matcher_domain, - {"source": config_entries.SOURCE_ZEROCONF}, + context, info, ) diff --git a/tests/components/zeroconf/test_init.py b/tests/components/zeroconf/test_init.py index 6bc37e10da2..0de9929fcf8 100644 --- a/tests/components/zeroconf/test_init.py +++ b/tests/components/zeroconf/test_init.py @@ -327,6 +327,7 @@ async def test_zeroconf_match_macaddress(hass, mock_async_zeroconf): assert len(mock_service_browser.mock_calls) == 1 assert len(mock_config_flow.mock_calls) == 1 assert mock_config_flow.mock_calls[0][1][0] == "shelly" + assert mock_config_flow.mock_calls[0][2]["context"] == {"source": "zeroconf"} async def test_zeroconf_match_manufacturer(hass, mock_async_zeroconf): @@ -533,6 +534,10 @@ async def test_homekit_match_partial_space(hass, mock_async_zeroconf): # One for HKC, and one for LIFX since lifx is local polling assert len(mock_config_flow.mock_calls) == 2 assert mock_config_flow.mock_calls[0][1][0] == "lifx" + assert mock_config_flow.mock_calls[1][2]["context"] == { + "source": "zeroconf", + "alternative_domain": "lifx", + } async def test_homekit_match_partial_dash(hass, mock_async_zeroconf):