mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Prevent the zeroconf service browser from terminating when a device without any addresses is discovered. (#38094)
This commit is contained in:
parent
5583f43030
commit
fdc5208d18
@ -210,6 +210,11 @@ def setup(hass, config):
|
|||||||
return
|
return
|
||||||
|
|
||||||
info = info_from_service(service_info)
|
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)
|
_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.
|
||||||
@ -317,6 +322,9 @@ def info_from_service(service):
|
|||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if not service.addresses:
|
||||||
|
return None
|
||||||
|
|
||||||
address = service.addresses[0]
|
address = service.addresses[0]
|
||||||
|
|
||||||
info = {
|
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):
|
def get_homekit_info_mock(model, pairing_status):
|
||||||
"""Return homekit info for get_service_info for an homekit device."""
|
"""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
|
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):
|
async def test_get_instance(hass, mock_zeroconf):
|
||||||
"""Test we get an instance."""
|
"""Test we get an instance."""
|
||||||
assert await hass.components.zeroconf.async_get_instance() is mock_zeroconf
|
assert await hass.components.zeroconf.async_get_instance() is mock_zeroconf
|
||||||
|
Loading…
x
Reference in New Issue
Block a user