mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Homekit has two types (#44879)
This commit is contained in:
parent
2fb3be50ab
commit
caf14b78d1
@ -45,7 +45,11 @@ ATTR_TYPE = "type"
|
|||||||
ATTR_PROPERTIES = "properties"
|
ATTR_PROPERTIES = "properties"
|
||||||
|
|
||||||
ZEROCONF_TYPE = "_home-assistant._tcp.local."
|
ZEROCONF_TYPE = "_home-assistant._tcp.local."
|
||||||
HOMEKIT_TYPE = "_hap._tcp.local."
|
HOMEKIT_TYPES = [
|
||||||
|
"_hap._tcp.local.",
|
||||||
|
# Thread based devices
|
||||||
|
"_hap._udp.local.",
|
||||||
|
]
|
||||||
|
|
||||||
CONF_DEFAULT_INTERFACE = "default_interface"
|
CONF_DEFAULT_INTERFACE = "default_interface"
|
||||||
CONF_IPV6 = "ipv6"
|
CONF_IPV6 = "ipv6"
|
||||||
@ -229,8 +233,9 @@ async def _async_start_zeroconf_browser(hass, zeroconf):
|
|||||||
|
|
||||||
types = list(zeroconf_types)
|
types = list(zeroconf_types)
|
||||||
|
|
||||||
if HOMEKIT_TYPE not in zeroconf_types:
|
for hk_type in HOMEKIT_TYPES:
|
||||||
types.append(HOMEKIT_TYPE)
|
if hk_type not in zeroconf_types:
|
||||||
|
types.append(hk_type)
|
||||||
|
|
||||||
def service_update(zeroconf, service_type, name, state_change):
|
def service_update(zeroconf, service_type, name, state_change):
|
||||||
"""Service state changed."""
|
"""Service state changed."""
|
||||||
@ -261,7 +266,7 @@ async def _async_start_zeroconf_browser(hass, zeroconf):
|
|||||||
_LOGGER.debug("Discovered new device %s %s", name, info)
|
_LOGGER.debug("Discovered new device %s %s", name, info)
|
||||||
|
|
||||||
# If we can handle it as a HomeKit discovery, we do that here.
|
# If we can handle it as a HomeKit discovery, we do that here.
|
||||||
if service_type == HOMEKIT_TYPE:
|
if service_type in HOMEKIT_TYPES:
|
||||||
discovery_was_forwarded = handle_homekit(hass, homekit_models, info)
|
discovery_was_forwarded = handle_homekit(hass, homekit_models, info)
|
||||||
# Continue on here as homekit_controller
|
# Continue on here as homekit_controller
|
||||||
# still needs to get updates on devices
|
# still needs to get updates on devices
|
||||||
@ -294,7 +299,9 @@ async def _async_start_zeroconf_browser(hass, zeroconf):
|
|||||||
else:
|
else:
|
||||||
uppercase_mac = None
|
uppercase_mac = None
|
||||||
|
|
||||||
for entry in zeroconf_types[service_type]:
|
# Not all homekit types are currently used for discovery
|
||||||
|
# so not all service type exist in zeroconf_types
|
||||||
|
for entry in zeroconf_types.get(service_type, []):
|
||||||
if len(entry) > 1:
|
if len(entry) > 1:
|
||||||
if (
|
if (
|
||||||
uppercase_mac is not None
|
uppercase_mac is not None
|
||||||
|
@ -31,9 +31,11 @@ HOMEKIT_STATUS_UNPAIRED = b"1"
|
|||||||
HOMEKIT_STATUS_PAIRED = b"0"
|
HOMEKIT_STATUS_PAIRED = b"0"
|
||||||
|
|
||||||
|
|
||||||
def service_update_mock(zeroconf, services, handlers):
|
def service_update_mock(zeroconf, services, handlers, *, limit_service=None):
|
||||||
"""Call service update handler."""
|
"""Call service update handler."""
|
||||||
for service in services:
|
for service in services:
|
||||||
|
if limit_service is not None and service != limit_service:
|
||||||
|
continue
|
||||||
handlers[0](zeroconf, service, f"name.{service}", ServiceStateChange.Added)
|
handlers[0](zeroconf, service, f"name.{service}", ServiceStateChange.Added)
|
||||||
|
|
||||||
|
|
||||||
@ -307,12 +309,16 @@ async def test_homekit_match_partial_space(hass, mock_zeroconf):
|
|||||||
"""Test configured options for a device are loaded via config entry."""
|
"""Test configured options for a device are loaded via config entry."""
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
zc_gen.ZEROCONF,
|
zc_gen.ZEROCONF,
|
||||||
{zeroconf.HOMEKIT_TYPE: [{"domain": "homekit_controller"}]},
|
{"_hap._tcp.local.": [{"domain": "homekit_controller"}]},
|
||||||
clear=True,
|
clear=True,
|
||||||
), patch.object(
|
), patch.object(
|
||||||
hass.config_entries.flow, "async_init"
|
hass.config_entries.flow, "async_init"
|
||||||
) as mock_config_flow, patch.object(
|
) as mock_config_flow, patch.object(
|
||||||
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
|
zeroconf,
|
||||||
|
"HaServiceBrowser",
|
||||||
|
side_effect=lambda *args, **kwargs: service_update_mock(
|
||||||
|
*args, **kwargs, limit_service="_hap._tcp.local."
|
||||||
|
),
|
||||||
) as mock_service_browser:
|
) as mock_service_browser:
|
||||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
||||||
"LIFX bulb", HOMEKIT_STATUS_UNPAIRED
|
"LIFX bulb", HOMEKIT_STATUS_UNPAIRED
|
||||||
@ -330,12 +336,16 @@ async def test_homekit_match_partial_dash(hass, mock_zeroconf):
|
|||||||
"""Test configured options for a device are loaded via config entry."""
|
"""Test configured options for a device are loaded via config entry."""
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
zc_gen.ZEROCONF,
|
zc_gen.ZEROCONF,
|
||||||
{zeroconf.HOMEKIT_TYPE: [{"domain": "homekit_controller"}]},
|
{"_hap._udp.local.": [{"domain": "homekit_controller"}]},
|
||||||
clear=True,
|
clear=True,
|
||||||
), patch.object(
|
), patch.object(
|
||||||
hass.config_entries.flow, "async_init"
|
hass.config_entries.flow, "async_init"
|
||||||
) as mock_config_flow, patch.object(
|
) as mock_config_flow, patch.object(
|
||||||
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
|
zeroconf,
|
||||||
|
"HaServiceBrowser",
|
||||||
|
side_effect=lambda *args, **kwargs: service_update_mock(
|
||||||
|
*args, **kwargs, limit_service="_hap._udp.local."
|
||||||
|
),
|
||||||
) as mock_service_browser:
|
) as mock_service_browser:
|
||||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
||||||
"Rachio-fa46ba", HOMEKIT_STATUS_UNPAIRED
|
"Rachio-fa46ba", HOMEKIT_STATUS_UNPAIRED
|
||||||
@ -353,12 +363,16 @@ async def test_homekit_match_full(hass, mock_zeroconf):
|
|||||||
"""Test configured options for a device are loaded via config entry."""
|
"""Test configured options for a device are loaded via config entry."""
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
zc_gen.ZEROCONF,
|
zc_gen.ZEROCONF,
|
||||||
{zeroconf.HOMEKIT_TYPE: [{"domain": "homekit_controller"}]},
|
{"_hap._udp.local.": [{"domain": "homekit_controller"}]},
|
||||||
clear=True,
|
clear=True,
|
||||||
), patch.object(
|
), patch.object(
|
||||||
hass.config_entries.flow, "async_init"
|
hass.config_entries.flow, "async_init"
|
||||||
) as mock_config_flow, patch.object(
|
) as mock_config_flow, patch.object(
|
||||||
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
|
zeroconf,
|
||||||
|
"HaServiceBrowser",
|
||||||
|
side_effect=lambda *args, **kwargs: service_update_mock(
|
||||||
|
*args, **kwargs, limit_service="_hap._udp.local."
|
||||||
|
),
|
||||||
) as mock_service_browser:
|
) as mock_service_browser:
|
||||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
||||||
"BSB002", HOMEKIT_STATUS_UNPAIRED
|
"BSB002", HOMEKIT_STATUS_UNPAIRED
|
||||||
@ -376,12 +390,16 @@ async def test_homekit_already_paired(hass, mock_zeroconf):
|
|||||||
"""Test that an already paired device is sent to homekit_controller."""
|
"""Test that an already paired device is sent to homekit_controller."""
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
zc_gen.ZEROCONF,
|
zc_gen.ZEROCONF,
|
||||||
{zeroconf.HOMEKIT_TYPE: [{"domain": "homekit_controller"}]},
|
{"_hap._tcp.local.": [{"domain": "homekit_controller"}]},
|
||||||
clear=True,
|
clear=True,
|
||||||
), patch.object(
|
), patch.object(
|
||||||
hass.config_entries.flow, "async_init"
|
hass.config_entries.flow, "async_init"
|
||||||
) as mock_config_flow, patch.object(
|
) as mock_config_flow, patch.object(
|
||||||
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
|
zeroconf,
|
||||||
|
"HaServiceBrowser",
|
||||||
|
side_effect=lambda *args, **kwargs: service_update_mock(
|
||||||
|
*args, **kwargs, limit_service="_hap._tcp.local."
|
||||||
|
),
|
||||||
) as mock_service_browser:
|
) as mock_service_browser:
|
||||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
||||||
"tado", HOMEKIT_STATUS_PAIRED
|
"tado", HOMEKIT_STATUS_PAIRED
|
||||||
@ -400,12 +418,16 @@ async def test_homekit_invalid_paring_status(hass, mock_zeroconf):
|
|||||||
"""Test that missing paring data is not sent to homekit_controller."""
|
"""Test that missing paring data is not sent to homekit_controller."""
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
zc_gen.ZEROCONF,
|
zc_gen.ZEROCONF,
|
||||||
{zeroconf.HOMEKIT_TYPE: [{"domain": "homekit_controller"}]},
|
{"_hap._tcp.local.": [{"domain": "homekit_controller"}]},
|
||||||
clear=True,
|
clear=True,
|
||||||
), patch.object(
|
), patch.object(
|
||||||
hass.config_entries.flow, "async_init"
|
hass.config_entries.flow, "async_init"
|
||||||
) as mock_config_flow, patch.object(
|
) as mock_config_flow, patch.object(
|
||||||
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
|
zeroconf,
|
||||||
|
"HaServiceBrowser",
|
||||||
|
side_effect=lambda *args, **kwargs: service_update_mock(
|
||||||
|
*args, **kwargs, limit_service="_hap._tcp.local."
|
||||||
|
),
|
||||||
) as mock_service_browser:
|
) as mock_service_browser:
|
||||||
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
|
||||||
"tado", b"invalid"
|
"tado", b"invalid"
|
||||||
@ -423,7 +445,7 @@ async def test_homekit_not_paired(hass, mock_zeroconf):
|
|||||||
"""Test that an not paired device is sent to homekit_controller."""
|
"""Test that an not paired device is sent to homekit_controller."""
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
zc_gen.ZEROCONF,
|
zc_gen.ZEROCONF,
|
||||||
{zeroconf.HOMEKIT_TYPE: [{"domain": "homekit_controller"}]},
|
{"_hap._tcp.local.": [{"domain": "homekit_controller"}]},
|
||||||
clear=True,
|
clear=True,
|
||||||
), patch.object(
|
), patch.object(
|
||||||
hass.config_entries.flow, "async_init"
|
hass.config_entries.flow, "async_init"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user