Prevent the zeroconf service browser from terminating when a device without any addresses is discovered. (#38094)
parent
5583f43030
commit
fdc5208d18
|
@ -210,6 +210,11 @@ def setup(hass, config):
|
|||
return
|
||||
|
||||
info = info_from_service(service_info)
|
||||
if not info:
|
||||
# Prevent the browser thread from collapsing
|
||||
_LOGGER.debug("Failed to get addresses for device %s", name)
|
||||
return
|
||||
|
||||
_LOGGER.debug("Discovered new device %s %s", name, info)
|
||||
|
||||
# If we can handle it as a HomeKit discovery, we do that here.
|
||||
|
@ -317,6 +322,9 @@ def info_from_service(service):
|
|||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
if not service.addresses:
|
||||
return None
|
||||
|
||||
address = service.addresses[0]
|
||||
|
||||
info = {
|
||||
|
|
|
@ -49,6 +49,20 @@ def get_service_info_mock(service_type, name):
|
|||
)
|
||||
|
||||
|
||||
def get_service_info_mock_without_an_address(service_type, name):
|
||||
"""Return service info for get_service_info without any addresses."""
|
||||
return ServiceInfo(
|
||||
service_type,
|
||||
name,
|
||||
addresses=[],
|
||||
port=80,
|
||||
weight=0,
|
||||
priority=0,
|
||||
server="name.local.",
|
||||
properties=PROPERTIES,
|
||||
)
|
||||
|
||||
|
||||
def get_homekit_info_mock(model, pairing_status):
|
||||
"""Return homekit info for get_service_info for an homekit device."""
|
||||
|
||||
|
@ -308,6 +322,15 @@ async def test_info_from_service_non_utf8(hass):
|
|||
assert raw_info["non-utf8-value"] is NON_UTF8_VALUE
|
||||
|
||||
|
||||
async def test_info_from_service_with_addresses(hass):
|
||||
"""Test info_from_service does not throw when there are no addresses."""
|
||||
service_type = "_test._tcp.local."
|
||||
info = zeroconf.info_from_service(
|
||||
get_service_info_mock_without_an_address(service_type, f"test.{service_type}")
|
||||
)
|
||||
assert info is None
|
||||
|
||||
|
||||
async def test_get_instance(hass, mock_zeroconf):
|
||||
"""Test we get an instance."""
|
||||
assert await hass.components.zeroconf.async_get_instance() is mock_zeroconf
|
||||
|
|
Loading…
Reference in New Issue