Connection module#
Connection helpers for discovering and managing wired GoPro devices.
Utilities to create connection objects for GoPro devices, scan for devices over USB/mdns, and manage open/close life-cycle of WiredConnection objects.
- class pytermite.connection.WiredConnection(**kwargs: Any)[source]#
Subclass of
WiredGoProproviding a cached human-readable name.- Parameters:
**kwargs – All keyword arguments are passed to the
WiredGoProconstructor. The name keyword is reserved for an optional cached camera name that can be provided on initialization. If not provided, the name will be lazily loaded on first access by querying the camera’s information via the HTTP API and falling back to a name derived from the serial numbers mapping.- Attributes:
ble_commandUsed to call the BLE commands
ble_settingUsed to access the BLE settings
ble_statusUsed to access the BLE statuses
http_commandUsed to access the USB commands
http_settingUsed to access the USB settings
identifierUnique identifier for the connected GoPro Client
ip_addressThe IP address of the GoPro device
is_ble_connectedAre we connected via BLE to the GoPro device?
is_cohn_provisionedIs COHN currently provisioned?
is_http_connectedAre we connected via Wifi to the GoPro device?
is_openIs this client ready for communication?
is_readyIs gopro ready to receive commands
nameAsynchronously return the human-friendly name of the camera.
versionThe Open GoPro API version of the GoPro Client
Methods
close()Gracefully close the GoPro Client connection
configure_cohn([timeout])Prepare Camera on the Home Network
open([timeout, retries])Connect to the Wired GoPro Client and prepare it for communication
register_update(callback, update)Register for callbacks when an update occurs
unregister_update(callback[, update])Unregister for asynchronous update(s)
- property name: str#
Asynchronously return the human-friendly name of the camera.
If the name has not been determined yet this will query the camera for its information via the HTTP API and fall back to a name derived from the serial numbers mapping.
- Returns:
The camera name.
- Return type:
str
- async pytermite.connection.close_gopros(gopros: dict[str, WiredConnection] | set[WiredConnection]) None[source]#
Close all provided
WiredConnectionobjects.- Parameters:
gopros (dict[str, WiredConnection] | set[WiredConnection]) – Mapping of camera keys to
WiredConnectionobjects to close.
- async pytermite.connection.connect_gopros(gopros: dict[str, WiredConnection]) AsyncGenerator[WiredConnection, None][source]#
Attempt to open a connection to each provided
WiredConnection.This is an async generator that yields each connected
WiredConnection.- Parameters:
gopros (dict[str, WiredConnection]) – Mapping of camera keys to
WiredConnectionobjects to connect.- Yields:
WiredConnection – Each successfully connected
WiredConnectionobject.
- pytermite.connection.create_wired_gopros(gopro_serials: dict[str, str] | set[str]) dict[str, WiredConnection][source]#
Create
WiredConnectionobjects for provided serial numbers.- Parameters:
gopro_serials (dict[str, str] | set[str]) – Mapping from camera name to serial number, or a set of serial numbers.
- Returns:
Mapping from provided key (camera name or serial) to a
WiredConnectioninstance.- Return type:
dict[str, WiredConnection]
- async pytermite.connection.scan_for_gopros(waiting_time: int = 10) set[str][source]#
Scan for connected GoPro devices via USB connection and return a set of serials.
The scan runs until either the user requests to stop (press Enter) or the timeout happens. Both are executed concurrently alongside the USB scanning task.
- Parameters:
waiting_time (int, optional) – Maximum seconds to wait for discovery. Default is 10.
- Returns:
Set of discovered device serial numbers (strings).
- Return type:
set[str]
- async pytermite.connection.scan_for_gopros_usb() None[source]#
Continuously scan for GoPro devices via mDNS until interrupted.
- async pytermite.connection.wait_for_user_interrupt() None[source]#
Wait for the user to press Enter using a non-blocking stdin reader.
Notes
Uses the event loop’s
add_readerAPI so the waiter can be cancelled immediately (the reader is removed in the finally block). This avoids the problem where awaiting a blocking input call prevents task cancellation.