--- layout: template title: API - pyatv.helpers permalink: /api//helpers link_group: api ---

Module pyatv.helpers

Various helper methods.

Functions

async def auto_connect(handler: Callable[[AppleTV], NoneType], timeout: int = 5, not_found: Callable[[], NoneType] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None) -> NoneType

Connect to first discovered device.

This is a convenience method that auto discovers devices, picks the first device found, connects to it and passes it to a user provided handler. An optional error handler can be provided that is called when no device was found. Very inflexible in many cases, but can be handys sometimes when trying things.

Note: both handler and not_found must be coroutines

def get_unique_id(service_type: str, service_name: str, properties: Mapping[str, str]) -> Optional[str]

Return unique identifier from a Zeroconf service.

service_type is the Zeroconf service type (e.g. _mediaremotetv._tcp.local), service_name name of the service (e.g. Office or Living Room) and properties all key-value properties belonging to the service.

The unique identifier is returned if available, otherwise None is returned.