feat: make async_get_service_info available on the Zeroconf object (#… · python-zeroconf/python-zeroconf@c4c2dee
@@ -39,7 +39,11 @@
3939from ._protocol.outgoing import DNSOutgoing
4040from ._services import ServiceListener
4141from ._services.browser import ServiceBrowser
42-from ._services.info import ServiceInfo, instance_name_from_service_info
42+from ._services.info import (
43+AsyncServiceInfo,
44+ServiceInfo,
45+instance_name_from_service_info,
46+)
4347from ._services.registry import ServiceRegistry
4448from ._transport import _WrappedTransport
4549from ._updates import RecordUpdateListener
@@ -261,7 +265,13 @@ def get_service_info(
261265 ) -> Optional[ServiceInfo]:
262266"""Returns network's service information for a particular
263267 name and type, or None if no service matches by the timeout,
264- which defaults to 3 seconds."""
268+ which defaults to 3 seconds.
269+270+ :param type_: fully qualified service type name
271+ :param name: the name of the service
272+ :param timeout: milliseconds to wait for a response
273+ :param question_type: The type of questions to ask (DNSQuestionType.QM or DNSQuestionType.QU)
274+ """
265275info = ServiceInfo(type_, name)
266276if info.request(self, timeout, question_type):
267277return info
@@ -360,6 +370,23 @@ async def async_update_service(self, info: ServiceInfo) -> Awaitable:
360370self.registry.async_update(info)
361371return asyncio.ensure_future(self._async_broadcast_service(info, _REGISTER_TIME, None))
362372373+async def async_get_service_info(
374+self, type_: str, name: str, timeout: int = 3000, question_type: Optional[DNSQuestionType] = None
375+ ) -> Optional[AsyncServiceInfo]:
376+"""Returns network's service information for a particular
377+ name and type, or None if no service matches by the timeout,
378+ which defaults to 3 seconds.
379+380+ :param type_: fully qualified service type name
381+ :param name: the name of the service
382+ :param timeout: milliseconds to wait for a response
383+ :param question_type: The type of questions to ask (DNSQuestionType.QM or DNSQuestionType.QU)
384+ """
385+info = AsyncServiceInfo(type_, name)
386+if await info.async_request(self, timeout, question_type):
387+return info
388+return None
389+363390async def _async_broadcast_service(
364391self,
365392info: ServiceInfo,