mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Use shared zeroconf for discovery netdisco (#37237)
* Use shared zeroconf for netdisco * Update netdisco Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
0f43476d03
commit
fae47358b8
@ -14,6 +14,7 @@ from netdisco.discovery import NetworkDiscovery
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -147,6 +148,8 @@ async def async_setup(hass, config):
|
|||||||
platform,
|
platform,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||||
|
|
||||||
async def new_service_found(service, info):
|
async def new_service_found(service, info):
|
||||||
"""Handle a new service if one is found."""
|
"""Handle a new service if one is found."""
|
||||||
if service in MIGRATED_SERVICE_HANDLERS:
|
if service in MIGRATED_SERVICE_HANDLERS:
|
||||||
@ -193,7 +196,7 @@ async def async_setup(hass, config):
|
|||||||
async def scan_devices(now):
|
async def scan_devices(now):
|
||||||
"""Scan for devices."""
|
"""Scan for devices."""
|
||||||
try:
|
try:
|
||||||
results = await hass.async_add_job(_discover, netdisco)
|
results = await hass.async_add_job(_discover, netdisco, zeroconf_instance)
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
hass.async_create_task(new_service_found(*result))
|
hass.async_create_task(new_service_found(*result))
|
||||||
@ -214,11 +217,11 @@ async def async_setup(hass, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _discover(netdisco):
|
def _discover(netdisco, zeroconf_instance):
|
||||||
"""Discover devices."""
|
"""Discover devices."""
|
||||||
results = []
|
results = []
|
||||||
try:
|
try:
|
||||||
netdisco.scan()
|
netdisco.scan(zeroconf_instance=zeroconf_instance)
|
||||||
|
|
||||||
for disc in netdisco.discover():
|
for disc in netdisco.discover():
|
||||||
for service in netdisco.get_info(disc):
|
for service in netdisco.get_info(disc):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "discovery",
|
"domain": "discovery",
|
||||||
"name": "Discovery",
|
"name": "Discovery",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/discovery",
|
"documentation": "https://www.home-assistant.io/integrations/discovery",
|
||||||
"requirements": ["netdisco==2.7.1"],
|
"requirements": ["netdisco==2.8.0"],
|
||||||
"after_dependencies": ["zeroconf"],
|
"after_dependencies": ["zeroconf"],
|
||||||
"codeowners": [],
|
"codeowners": [],
|
||||||
"quality_scale": "internal"
|
"quality_scale": "internal"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "ssdp",
|
"domain": "ssdp",
|
||||||
"name": "Simple Service Discovery Protocol (SSDP)",
|
"name": "Simple Service Discovery Protocol (SSDP)",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/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"],
|
"after_dependencies": ["zeroconf"],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ hass-nabucasa==0.34.7
|
|||||||
home-assistant-frontend==20200629.0
|
home-assistant-frontend==20200629.0
|
||||||
importlib-metadata==1.6.0;python_version<'3.8'
|
importlib-metadata==1.6.0;python_version<'3.8'
|
||||||
jinja2>=2.11.1
|
jinja2>=2.11.1
|
||||||
netdisco==2.7.1
|
netdisco==2.8.0
|
||||||
pip>=8.0.3
|
pip>=8.0.3
|
||||||
python-slugify==4.0.0
|
python-slugify==4.0.0
|
||||||
pytz>=2020.1
|
pytz>=2020.1
|
||||||
|
@ -953,7 +953,7 @@ netdata==0.2.0
|
|||||||
|
|
||||||
# homeassistant.components.discovery
|
# homeassistant.components.discovery
|
||||||
# homeassistant.components.ssdp
|
# homeassistant.components.ssdp
|
||||||
netdisco==2.7.1
|
netdisco==2.8.0
|
||||||
|
|
||||||
# homeassistant.components.neurio_energy
|
# homeassistant.components.neurio_energy
|
||||||
neurio==0.3.1
|
neurio==0.3.1
|
||||||
|
@ -424,7 +424,7 @@ nessclient==0.9.15
|
|||||||
|
|
||||||
# homeassistant.components.discovery
|
# homeassistant.components.discovery
|
||||||
# homeassistant.components.ssdp
|
# homeassistant.components.ssdp
|
||||||
netdisco==2.7.1
|
netdisco==2.8.0
|
||||||
|
|
||||||
# homeassistant.components.nexia
|
# homeassistant.components.nexia
|
||||||
nexia==0.9.3
|
nexia==0.9.3
|
||||||
|
@ -58,7 +58,7 @@ async def mock_discovery(hass, discoveries, config=BASE_CONFIG):
|
|||||||
async def test_unknown_service(hass):
|
async def test_unknown_service(hass):
|
||||||
"""Test that unknown service is ignored."""
|
"""Test that unknown service is ignored."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco, zeroconf_instance):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [("this_service_will_never_be_supported", {"info": "some"})]
|
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):
|
async def test_load_platform(hass):
|
||||||
"""Test load a platform."""
|
"""Test load a platform."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco, zeroconf_instance):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE, SERVICE_INFO)]
|
return [(SERVICE, SERVICE_INFO)]
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ async def test_load_platform(hass):
|
|||||||
async def test_load_component(hass):
|
async def test_load_component(hass):
|
||||||
"""Test load a component."""
|
"""Test load a component."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco, zeroconf_instance):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ async def test_load_component(hass):
|
|||||||
async def test_ignore_service(hass):
|
async def test_ignore_service(hass):
|
||||||
"""Test ignore service."""
|
"""Test ignore service."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco, zeroconf_instance):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ async def test_ignore_service(hass):
|
|||||||
async def test_discover_duplicates(hass):
|
async def test_discover_duplicates(hass):
|
||||||
"""Test load a component."""
|
"""Test load a component."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco, zeroconf_instance):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [
|
return [
|
||||||
(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
||||||
@ -145,7 +145,7 @@ async def test_discover_config_flow(hass):
|
|||||||
"""Test discovery triggering a config flow."""
|
"""Test discovery triggering a config flow."""
|
||||||
discovery_info = {"hello": "world"}
|
discovery_info = {"hello": "world"}
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco, zeroconf_instance):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [("mock-service", discovery_info)]
|
return [("mock-service", discovery_info)]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user