Skip to content

Commit

Permalink
Fix homekit_controller discovery via zeroconf (#37725)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored and balloob committed Jul 14, 2020
1 parent 502f0cd commit 6eca0b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions homeassistant/components/zeroconf/__init__.py
Expand Up @@ -200,7 +200,7 @@ def service_update(zeroconf, service_type, name, state_change):

# If we can handle it as a HomeKit discovery, we do that here.
if service_type == HOMEKIT_TYPE:
handle_homekit(hass, info)
discovery_was_forwarded = handle_homekit(hass, info)
# Continue on here as homekit_controller
# still needs to get updates on devices
# so it can see when the 'c#' field is updated.
Expand All @@ -209,7 +209,8 @@ def service_update(zeroconf, service_type, name, state_change):
# if the device is already paired in order to avoid
# offering a second discovery for the same device
if (
HOMEKIT_PROPERTIES in info
discovery_was_forwarded
and HOMEKIT_PROPERTIES in info
and HOMEKIT_PAIRED_STATUS_FLAG in info[HOMEKIT_PROPERTIES]
):
try:
Expand Down
19 changes: 19 additions & 0 deletions tests/components/zeroconf/test_init.py
Expand Up @@ -215,6 +215,25 @@ async def test_homekit_invalid_paring_status(hass, mock_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "tado"


async def test_homekit_not_paired(hass, mock_zeroconf):
"""Test that an not paired device is sent to homekit_controller."""
with patch.dict(
zc_gen.ZEROCONF, {zeroconf.HOMEKIT_TYPE: ["homekit_controller"]}, clear=True
), patch.object(
hass.config_entries.flow, "async_init"
) as mock_config_flow, patch.object(
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
) as mock_service_browser:
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
"this_will_not_match_any_integration", HOMEKIT_STATUS_UNPAIRED
)
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})

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] == "homekit_controller"


async def test_info_from_service_non_utf8(hass):
"""Test info_from_service handles non UTF-8 property keys and values correctly."""
service_type = "_test._tcp.local."
Expand Down

0 comments on commit 6eca0b2

Please sign in to comment.