platypush/plugins/zeroconf/__init__.py
def discover_service(self, service: Union[str, list], timeout: Optional[int] = 5) -> Dict[str, Any]:
        """
        Find all the services matching the specified type.

        :param service: Service type (e.g. ``_http._tcp.local.``) or list of service types.
        :param timeout: Browser timeout in seconds (default: 5). Specify None for no timeout - in such case the
            discovery will loop forever and generate events upon service changes.
        :return: A ``service_type -> [service_names]`` mapping. Example:

          .. code-block:: json

            {
                "host1._platypush-http._tcp.local.": {
                    "type": "_platypush-http._tcp.local.",
                    "name": "host1._platypush-http._tcp.local.",
                    "info": {
                        "addresses": ["192.168.1.11"],
                        "port": 8008,
                        "host_ttl": 120,
                        "other_ttl": 4500,
                        "priority": 0,
                        "properties": {
                            "name": "Platypush",
                            "vendor": "Platypush",
                            "version": "0.13.2"
                        },
                        "server": "host1._platypush-http._tcp.local.",
                        "weight": 0
                    }
                }
            }

        """
        assert not self._discovery_in_progress, 'A discovery process is already running'
        self._discovery_in_progress = True

        evt_queue = queue.Queue()
        zc = Zeroconf()
        listener = ZeroconfListener(evt_queue=evt_queue)
        discovery_start = time.time()
        services = {}
        browser = None

        try:
            browser = ServiceBrowser(zc, service, listener)

            while timeout and time.time() - discovery_start < timeout:
                to = discovery_start + timeout - time.time() if timeout else None
                try:
                    evt = evt_queue.get(block=True, timeout=to)
                    if isinstance(evt, ZeroconfServiceAddedEvent) or isinstance(evt, ZeroconfServiceUpdatedEvent):
                        services[evt.service_name] = {
                            'type': evt.service_type,
                            'name': evt.service_name,
                            'info': evt.service_info,
                        }
                    elif isinstance(evt, ZeroconfServiceRemovedEvent):
                        if evt.service_name in services:
                            del services[evt.service_name]

                    get_bus().post(evt)
                except queue.Empty:
                    if not services:
                        self.logger.warning('No such service discovered: {}'.format(service))
        finally:
            if browser:
                browser.cancel()
            zc.close()
            self._discovery_in_progress = False

        return services

        Find all the services matching the specified type.

        :param service: Service type (e.g. ``_http._tcp.local.``) or list of service types.
        :param timeout: Browser timeout in seconds (default: 5). Specify None for no timeout - in such case the
            discovery will loop forever and generate events upon service changes.
        :return: A ``service_type -> [service_names]`` mapping. Example:

          .. code-block:: json

            {
                "host1._platypush-http._tcp.local.": {
                    "type": "_platypush-http._tcp.local.",
                    "name": "host1._platypush-http._tcp.local.",
                    "info": {
                        "addresses": ["192.168.1.11"],
                        "port": 8008,
                        "host_ttl": 120,
                        "other_ttl": 4500,
                        "priority": 0,
                        "properties": {
                            "name": "Platypush",
                            "vendor": "Platypush",
                            "version": "0.13.2"
                        },
                        "server": "host1._platypush-http._tcp.local.",
                        "weight": 0
                    }
                }
            }

        
Find all the services matching the specified type.
Find all the services matching the specified type .
def discover_service(self, service: Union[str, list], timeout: Optional[int] = 5) -> Dict[str, Any]:
        assert not self._discovery_in_progress, 'A discovery process is already running'
        self._discovery_in_progress = True
        evt_queue = queue.Queue()
        zc = Zeroconf()
        listener = ZeroconfListener(evt_queue=evt_queue)
        discovery_start = time.time()
        services = {}
        browser = None
        try:
            browser = ServiceBrowser(zc, service, listener)
            while timeout and time.time() - discovery_start < timeout:
                to = discovery_start + timeout - time.time() if timeout else None
                try:
                    evt = evt_queue.get(block=True, timeout=to)
                    if isinstance(evt, ZeroconfServiceAddedEvent) or isinstance(evt, ZeroconfServiceUpdatedEvent):
                        services[evt.service_name] = {
                            'type': evt.service_type,
                            'name': evt.service_name,
                            'info': evt.service_info,
                        }
                    elif isinstance(evt, ZeroconfServiceRemovedEvent):
                        if evt.service_name in services:
                            del services[evt.service_name]
                    get_bus().post(evt)
                except queue.Empty:
                    if not services:
                        self.logger.warning('No such service discovered: {}'.format(service))
        finally:
            if browser:
                browser.cancel()
            zc.close()
            self._discovery_in_progress = False
        return services
def discover_service ( self , service : Union [ str , list ] , timeout : Optional [ int ] = 5 ) -> Dict [ str , Any ] : assert not self . _discovery_in_progress , 'A discovery process is already running' self . _discovery_in_progress = True evt_queue = queue . Queue ( ) zc = Zeroconf ( ) listener = ZeroconfListener ( evt_queue = evt_queue ) discovery_start = time . time ( ) services = { } browser = None try : browser = ServiceBrowser ( zc , service , listener ) while timeout and time . time ( ) - discovery_start < timeout : to = discovery_start + timeout - time . time ( ) if timeout else None try : evt = evt_queue . get ( block = True , timeout = to ) if isinstance ( evt , ZeroconfServiceAddedEvent ) or isinstance ( evt , ZeroconfServiceUpdatedEvent ) : services [ evt . service_name ] = { 'type' : evt . service_type , 'name' : evt . service_name , 'info' : evt . service_info , } elif isinstance ( evt , ZeroconfServiceRemovedEvent ) : if evt . service_name in services : del services [ evt . service_name ] get_bus ( ) . post ( evt ) except queue . Empty : if not services : self . logger . warning ( 'No such service discovered: {}' . format ( service ) ) finally : if browser : browser . cancel ( ) zc . close ( ) self . _discovery_in_progress = False return services
Find all the services matching the specified type.
Find all the services matching the specified type .
"""
        Find all the services matching the specified type.

        :param service: Service type (e.g. ``_http._tcp.local.``) or list of service types.
        :param timeout: Browser timeout in seconds (default: 5). Specify None for no timeout - in such case the
            discovery will loop forever and generate events upon service changes.
        :return: A ``service_type -> [service_names]`` mapping. Example:

          .. code-block:: json

            {
                "host1._platypush-http._tcp.local.": {
                    "type": "_platypush-http._tcp.local.",
                    "name": "host1._platypush-http._tcp.local.",
                    "info": {
                        "addresses": ["192.168.1.11"],
                        "port": 8008,
                        "host_ttl": 120,
                        "other_ttl": 4500,
                        "priority": 0,
                        "properties": {
                            "name": "Platypush",
                            "vendor": "Platypush",
                            "version": "0.13.2"
                        },
                        "server": "host1._platypush-http._tcp.local.",
                        "weight": 0
                    }
                }
            }

        """
A ``service_type -> [service_names]`` mapping. Example:
code-block:: json


A ` ` service_type - > [ service_names ] ` ` mapping . Example : code - block :: json
self
service
Union[str, list]
Service type  or list of service types.
Service type or list of service types .
timeout
Optional[int]
Browser timeout in seconds (default: 5). Specify None for no timeout - in such case the
discovery will loop forever and generate events upon service changes.
Browser timeout in seconds ( default : 5 ) . Specify None for no timeout - in such case the discovery will loop forever and generate events upon service changes .