def setup(hass, config):
    logger = logging.getLogger(__name__)

    from netdisco.service import DiscoveryService

    # Disable zeroconf logging, it spams
    logging.getLogger('zeroconf').setLevel(logging.CRITICAL)

    lock = threading.Lock()

    def new_service_listener(service, info):
        """Called when a new service is found."""
        with lock:
            logger.info("Found new service: %s %s", service, info)

            component = SERVICE_HANDLERS.get(service)

            # We do not know how to handle this service.
            if not component:
                return

            # This component cannot be setup.
            if not bootstrap.setup_component(hass, component, config):
                return

            hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
                ATTR_SERVICE: service,
                ATTR_DISCOVERED: info
            })

    # pylint: disable=unused-argument
    def start_discovery(event):
        """Start discovering."""
        netdisco = DiscoveryService(SCAN_INTERVAL)
        netdisco.add_listener(new_service_listener)
        netdisco.start()

    hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_discovery)

    return True
Start a discovery service.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/discovery.py/setup