Store alternative domain for Zeroconf homekit discovery (#79240)

This commit is contained in:
Paulus Schoutsen 2022-09-29 22:21:00 -04:00 committed by GitHub
parent aa6f15b1e2
commit 6e893d9162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

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

View File

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