Use a single service browser for zeroconf discovery (#35997)

This commit is contained in:
J. Nick Koston 2020-05-23 11:05:41 -05:00 committed by GitHub
parent cda2da62cf
commit b0578018cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 11 deletions

View File

@ -98,7 +98,7 @@ class HaServiceBrowser(ServiceBrowser):
# To avoid overwhemling the system we pre-filter here and only process # To avoid overwhemling the system we pre-filter here and only process
# DNSPointers for the configured record name (type) # DNSPointers for the configured record name (type)
# #
if record.name != self.type or not isinstance(record, DNSPointer): if record.name not in self.types or not isinstance(record, DNSPointer):
return return
super().update_record(zc, now, record) super().update_record(zc, now, record)
@ -224,11 +224,12 @@ def setup(hass, config):
) )
) )
for service in ZEROCONF: types = list(ZEROCONF)
HaServiceBrowser(zeroconf, service, handlers=[service_update])
if HOMEKIT_TYPE not in ZEROCONF: if HOMEKIT_TYPE not in ZEROCONF:
HaServiceBrowser(zeroconf, HOMEKIT_TYPE, handlers=[service_update]) types.append(HOMEKIT_TYPE)
HaServiceBrowser(zeroconf, types, handlers=[service_update])
return True return True

View File

@ -2,7 +2,7 @@
"domain": "zeroconf", "domain": "zeroconf",
"name": "Zero-configuration networking (zeroconf)", "name": "Zero-configuration networking (zeroconf)",
"documentation": "https://www.home-assistant.io/integrations/zeroconf", "documentation": "https://www.home-assistant.io/integrations/zeroconf",
"requirements": ["zeroconf==0.26.1"], "requirements": ["zeroconf==0.26.2"],
"dependencies": ["api"], "dependencies": ["api"],
"codeowners": ["@robbiet480", "@Kane610"], "codeowners": ["@robbiet480", "@Kane610"],
"quality_scale": "internal" "quality_scale": "internal"

View File

@ -25,7 +25,7 @@ ruamel.yaml==0.15.100
sqlalchemy==1.3.17 sqlalchemy==1.3.17
voluptuous-serialize==2.3.0 voluptuous-serialize==2.3.0
voluptuous==0.11.7 voluptuous==0.11.7
zeroconf==0.26.1 zeroconf==0.26.2
pycryptodome>=3.6.6 pycryptodome>=3.6.6

View File

@ -2239,7 +2239,7 @@ youtube_dl==2020.05.08
zengge==0.2 zengge==0.2
# homeassistant.components.zeroconf # homeassistant.components.zeroconf
zeroconf==0.26.1 zeroconf==0.26.2
# homeassistant.components.zha # homeassistant.components.zha
zha-quirks==0.0.39 zha-quirks==0.0.39

View File

@ -906,7 +906,7 @@ xmltodict==0.12.0
ya_ma==0.3.8 ya_ma==0.3.8
# homeassistant.components.zeroconf # homeassistant.components.zeroconf
zeroconf==0.26.1 zeroconf==0.26.2
# homeassistant.components.zha # homeassistant.components.zha
zha-quirks==0.0.39 zha-quirks==0.0.39

View File

@ -29,8 +29,9 @@ def mock_zeroconf():
yield mock_zc.return_value yield mock_zc.return_value
def service_update_mock(zeroconf, service, handlers): def service_update_mock(zeroconf, services, handlers):
"""Call service update handler.""" """Call service update handler."""
for service in services:
handlers[0](zeroconf, service, f"name.{service}", ServiceStateChange.Added) handlers[0](zeroconf, service, f"name.{service}", ServiceStateChange.Added)
@ -76,7 +77,7 @@ async def test_setup(hass, mock_zeroconf):
mock_zeroconf.get_service_info.side_effect = get_service_info_mock mock_zeroconf.get_service_info.side_effect = get_service_info_mock
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}}) assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
assert len(mock_service_browser.mock_calls) == len(zc_gen.ZEROCONF) assert len(mock_service_browser.mock_calls) == 1
expected_flow_calls = 0 expected_flow_calls = 0
for matching_components in zc_gen.ZEROCONF.values(): for matching_components in zc_gen.ZEROCONF.values():
expected_flow_calls += len(matching_components) expected_flow_calls += len(matching_components)