From fae47358b84f5cd44c6a51696ed9a2b5c4bfb09b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 29 Jun 2020 19:34:38 -0500 Subject: [PATCH] Use shared zeroconf for discovery netdisco (#37237) * Use shared zeroconf for netdisco * Update netdisco Co-authored-by: Paulus Schoutsen --- homeassistant/components/discovery/__init__.py | 9 ++++++--- homeassistant/components/discovery/manifest.json | 2 +- homeassistant/components/ssdp/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/discovery/test_init.py | 12 ++++++------ 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/discovery/__init__.py b/homeassistant/components/discovery/__init__.py index 1c2f816ad40..c39cb62c34c 100644 --- a/homeassistant/components/discovery/__init__.py +++ b/homeassistant/components/discovery/__init__.py @@ -14,6 +14,7 @@ from netdisco.discovery import NetworkDiscovery import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.const import EVENT_HOMEASSISTANT_START from homeassistant.core import callback import homeassistant.helpers.config_validation as cv @@ -147,6 +148,8 @@ async def async_setup(hass, config): platform, ) + zeroconf_instance = await zeroconf.async_get_instance(hass) + async def new_service_found(service, info): """Handle a new service if one is found.""" if service in MIGRATED_SERVICE_HANDLERS: @@ -193,7 +196,7 @@ async def async_setup(hass, config): async def scan_devices(now): """Scan for devices.""" try: - results = await hass.async_add_job(_discover, netdisco) + results = await hass.async_add_job(_discover, netdisco, zeroconf_instance) for result in results: hass.async_create_task(new_service_found(*result)) @@ -214,11 +217,11 @@ async def async_setup(hass, config): return True -def _discover(netdisco): +def _discover(netdisco, zeroconf_instance): """Discover devices.""" results = [] try: - netdisco.scan() + netdisco.scan(zeroconf_instance=zeroconf_instance) for disc in netdisco.discover(): for service in netdisco.get_info(disc): diff --git a/homeassistant/components/discovery/manifest.json b/homeassistant/components/discovery/manifest.json index 4b716b604f1..962ba9b8e8c 100644 --- a/homeassistant/components/discovery/manifest.json +++ b/homeassistant/components/discovery/manifest.json @@ -2,7 +2,7 @@ "domain": "discovery", "name": "Discovery", "documentation": "https://www.home-assistant.io/integrations/discovery", - "requirements": ["netdisco==2.7.1"], + "requirements": ["netdisco==2.8.0"], "after_dependencies": ["zeroconf"], "codeowners": [], "quality_scale": "internal" diff --git a/homeassistant/components/ssdp/manifest.json b/homeassistant/components/ssdp/manifest.json index d73bae27bb2..3dde2e9002e 100644 --- a/homeassistant/components/ssdp/manifest.json +++ b/homeassistant/components/ssdp/manifest.json @@ -2,7 +2,7 @@ "domain": "ssdp", "name": "Simple Service Discovery Protocol (SSDP)", "documentation": "https://www.home-assistant.io/integrations/ssdp", - "requirements": ["defusedxml==0.6.0", "netdisco==2.7.1"], + "requirements": ["defusedxml==0.6.0", "netdisco==2.8.0"], "after_dependencies": ["zeroconf"], "codeowners": [] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 70957391911..0a2f0a5d090 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -16,7 +16,7 @@ hass-nabucasa==0.34.7 home-assistant-frontend==20200629.0 importlib-metadata==1.6.0;python_version<'3.8' jinja2>=2.11.1 -netdisco==2.7.1 +netdisco==2.8.0 pip>=8.0.3 python-slugify==4.0.0 pytz>=2020.1 diff --git a/requirements_all.txt b/requirements_all.txt index 6eab3d3658e..d0ba8d8c7b3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -953,7 +953,7 @@ netdata==0.2.0 # homeassistant.components.discovery # homeassistant.components.ssdp -netdisco==2.7.1 +netdisco==2.8.0 # homeassistant.components.neurio_energy neurio==0.3.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a62951f422f..f4876770bdc 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -424,7 +424,7 @@ nessclient==0.9.15 # homeassistant.components.discovery # homeassistant.components.ssdp -netdisco==2.7.1 +netdisco==2.8.0 # homeassistant.components.nexia nexia==0.9.3 diff --git a/tests/components/discovery/test_init.py b/tests/components/discovery/test_init.py index 9490707e0f6..da04793e2a9 100644 --- a/tests/components/discovery/test_init.py +++ b/tests/components/discovery/test_init.py @@ -58,7 +58,7 @@ async def mock_discovery(hass, discoveries, config=BASE_CONFIG): async def test_unknown_service(hass): """Test that unknown service is ignored.""" - def discover(netdisco): + def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [("this_service_will_never_be_supported", {"info": "some"})] @@ -71,7 +71,7 @@ async def test_unknown_service(hass): async def test_load_platform(hass): """Test load a platform.""" - def discover(netdisco): + def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [(SERVICE, SERVICE_INFO)] @@ -87,7 +87,7 @@ async def test_load_platform(hass): async def test_load_component(hass): """Test load a component.""" - def discover(netdisco): + def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [(SERVICE_NO_PLATFORM, SERVICE_INFO)] @@ -107,7 +107,7 @@ async def test_load_component(hass): async def test_ignore_service(hass): """Test ignore service.""" - def discover(netdisco): + def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [(SERVICE_NO_PLATFORM, SERVICE_INFO)] @@ -120,7 +120,7 @@ async def test_ignore_service(hass): async def test_discover_duplicates(hass): """Test load a component.""" - def discover(netdisco): + def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [ (SERVICE_NO_PLATFORM, SERVICE_INFO), @@ -145,7 +145,7 @@ async def test_discover_config_flow(hass): """Test discovery triggering a config flow.""" discovery_info = {"hello": "world"} - def discover(netdisco): + def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [("mock-service", discovery_info)]