Searches the network for chromecast devices.

    If blocking = True, returns a list of discovered chromecast devices.
    If blocking = False, triggers a callback for each discovered chromecast,
                         and returns a function which can be executed to stop
                         discovery.

    May return an empty list if no chromecasts were found.

    Tries is specified if you want to limit the number of times the
    underlying socket associated with your Chromecast objects will
    retry connecting if connection is lost or it fails to connect
    in the first place. The number of seconds spent between each retry
    can be defined by passing the retry_wait parameter, the default is
    to wait 5 seconds.

def get_chromecasts(tries=None, retry_wait=None, timeout=None,
                    blocking=True, callback=None):
    """
    Searches the network for chromecast devices.

    If blocking = True, returns a list of discovered chromecast devices.
    If blocking = False, triggers a callback for each discovered chromecast,
                         and returns a function which can be executed to stop
                         discovery.

    May return an empty list if no chromecasts were found.

    Tries is specified if you want to limit the number of times the
    underlying socket associated with your Chromecast objects will
    retry connecting if connection is lost or it fails to connect
    in the first place. The number of seconds spent between each retry
    can be defined by passing the retry_wait parameter, the default is
    to wait 5 seconds.
    """
    if blocking:
        # Thread blocking chromecast discovery
        hosts = discover_chromecasts()
        cc_list = []
        for host in hosts:
            try:
                cc_list.append(_get_chromecast_from_host(
                    host, tries=tries, retry_wait=retry_wait, timeout=timeout,
                    blocking=blocking))
            except ChromecastConnectionError:  # noqa
                pass
        return cc_list
    else:
        # Callback based chromecast discovery
        if not callable(callback):
            raise ValueError(
                "Nonblocking discovery requires a callback function.")

        def internal_callback(name):
            """Called when zeroconf has discovered a new chromecast."""
            try:
                callback(_get_chromecast_from_host(
                    listener.services[name], tries=tries,
                    retry_wait=retry_wait, timeout=timeout, blocking=blocking))
            except ChromecastConnectionError:  # noqa
                pass

        def internal_stop():
            """Stops discovery of new chromecasts."""
            stop_discovery(browser)

        listener, browser = start_discovery(internal_callback)
        return internal_stop