mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Suppress duplicate mdns discovery from netdisco (#52099)
This commit is contained in:
parent
3c0a24db50
commit
ab24d16e00
@ -13,6 +13,7 @@ from homeassistant.core import callback
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import async_discover, async_load_platform
|
from homeassistant.helpers.discovery import async_discover, async_load_platform
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||||
|
from homeassistant.loader import async_get_zeroconf
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
DOMAIN = "discovery"
|
DOMAIN = "discovery"
|
||||||
@ -139,6 +140,10 @@ async def async_setup(hass, config):
|
|||||||
)
|
)
|
||||||
|
|
||||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||||
|
# Do not scan for types that have already been converted
|
||||||
|
# as it will generate excess network traffic for questions
|
||||||
|
# the zeroconf instance already knows the answers
|
||||||
|
zeroconf_types = list(await async_get_zeroconf(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."""
|
||||||
@ -187,7 +192,7 @@ async def async_setup(hass, config):
|
|||||||
"""Scan for devices."""
|
"""Scan for devices."""
|
||||||
try:
|
try:
|
||||||
results = await hass.async_add_executor_job(
|
results = await hass.async_add_executor_job(
|
||||||
_discover, netdisco, zeroconf_instance
|
_discover, netdisco, zeroconf_instance, zeroconf_types
|
||||||
)
|
)
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
@ -209,11 +214,13 @@ async def async_setup(hass, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _discover(netdisco, zeroconf_instance):
|
def _discover(netdisco, zeroconf_instance, zeroconf_types):
|
||||||
"""Discover devices."""
|
"""Discover devices."""
|
||||||
results = []
|
results = []
|
||||||
try:
|
try:
|
||||||
netdisco.scan(zeroconf_instance=zeroconf_instance)
|
netdisco.scan(
|
||||||
|
zeroconf_instance=zeroconf_instance, suppress_mdns_types=zeroconf_types
|
||||||
|
)
|
||||||
|
|
||||||
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.8.3"],
|
"requirements": ["netdisco==2.9.0"],
|
||||||
"after_dependencies": ["zeroconf"],
|
"after_dependencies": ["zeroconf"],
|
||||||
"codeowners": [],
|
"codeowners": [],
|
||||||
"quality_scale": "internal"
|
"quality_scale": "internal"
|
||||||
|
@ -1008,7 +1008,7 @@ nessclient==0.9.15
|
|||||||
netdata==0.2.0
|
netdata==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.discovery
|
# homeassistant.components.discovery
|
||||||
netdisco==2.8.3
|
netdisco==2.9.0
|
||||||
|
|
||||||
# homeassistant.components.nam
|
# homeassistant.components.nam
|
||||||
nettigo-air-monitor==1.0.0
|
nettigo-air-monitor==1.0.0
|
||||||
|
@ -562,7 +562,7 @@ ndms2_client==0.1.1
|
|||||||
nessclient==0.9.15
|
nessclient==0.9.15
|
||||||
|
|
||||||
# homeassistant.components.discovery
|
# homeassistant.components.discovery
|
||||||
netdisco==2.8.3
|
netdisco==2.9.0
|
||||||
|
|
||||||
# homeassistant.components.nam
|
# homeassistant.components.nam
|
||||||
nettigo-air-monitor==1.0.0
|
nettigo-air-monitor==1.0.0
|
||||||
|
@ -60,7 +60,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, zeroconf_instance):
|
def discover(netdisco, zeroconf_instance, suppress_mdns_types):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [("this_service_will_never_be_supported", {"info": "some"})]
|
return [("this_service_will_never_be_supported", {"info": "some"})]
|
||||||
|
|
||||||
@ -73,7 +73,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, zeroconf_instance):
|
def discover(netdisco, zeroconf_instance, suppress_mdns_types):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE, SERVICE_INFO)]
|
return [(SERVICE, SERVICE_INFO)]
|
||||||
|
|
||||||
@ -89,7 +89,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, zeroconf_instance):
|
def discover(netdisco, zeroconf_instance, suppress_mdns_types):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
@ -109,7 +109,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, zeroconf_instance):
|
def discover(netdisco, zeroconf_instance, suppress_mdns_types):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
@ -122,7 +122,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, zeroconf_instance):
|
def discover(netdisco, zeroconf_instance, suppress_mdns_types):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [
|
return [
|
||||||
(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
||||||
@ -147,7 +147,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, zeroconf_instance):
|
def discover(netdisco, zeroconf_instance, suppress_mdns_types):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [("mock-service", discovery_info)]
|
return [("mock-service", discovery_info)]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user