bluez_peripheral.adapter module

class bluez_peripheral.adapter.Adapter(proxy)[source]

Bases: object

A bluetooth adapter. Represents an org.bluez.Adapter1 instance.

Parameters:

proxy (ProxyObject)

async discover_devices(duration=10.0)[source]

Asynchronously search for other bluetooth devices.

Parameters:

duration (float) – The number of seconds to perform the discovery scan. Defaults to 10.0 seconds.

Return type:

AsyncIterator[Device]

get_adapter_interface()[source]

Returns the org.bluez.Adapter associated with this adapter.

Return type:

ProxyInterface

async get_address()[source]

Read the bluetooth address of this device.

Return type:

str

get_advertising_manager()[source]

Returns the org.bluez.LEAdvertisingManager1 interface associated with this adapter.

Return type:

ProxyInterface

async get_alias()[source]

The user friendly name of the device.

Return type:

str

async classmethod get_all(bus)[source]

Get a list of available Bluetooth adapters.

Parameters:

bus (MessageBus) – The message bus used to query bluez.

Returns:

A list of available bluetooth adapters.

Return type:

List[Adapter]

async get_devices()[source]

Returns a list of devices which have been discovered by this adapter.

Return type:

List[Device]

async get_discoverable()[source]

Indicates if the adapter is discoverable.

Return type:

bool

async get_discoverable_timeout()[source]

Get the current discoverable timeout

Return type:

int

async get_discovering()[source]

Returns true if the adapter is discovering. False otherwise.

Return type:

bool

async classmethod get_first(bus)[source]

Gets the first adapter listed by bluez.

Parameters:

bus (MessageBus) – The bus to use for adapter discovery.

Raises:

ValueError – Raised when no bluetooth adapters are available.

Returns:

The resulting adapter.

Return type:

Adapter

get_gatt_manager()[source]

Returns the org.bluez.GattManager1 interface associated with this adapter.

Return type:

ProxyInterface

async get_name()[source]

Read the bluetooth hostname of this system.

Return type:

str

async get_pairable()[source]

Indicates if the adapter is in pairable state or not.

Return type:

bool

async get_pairable_timeout()[source]

Get the current pairable timeout

Return type:

int

async get_powered()[source]

Indicates if the adapter is on or off.

Return type:

bool

async get_supported_advertising_includes()[source]

Returns a flag set of the advertising includes supported by this adapter.

Return type:

AdvertisingIncludes

async set_alias(val)[source]

Set the user friendly name for this device. Changing the device hostname directly is preferred. Writing an empty string will result in the alias resetting to the device hostname.

Parameters:

val (str)

Return type:

None

async set_discoverable(val)[source]

Switch an adapter to discoverable or non-discoverable to either make it visible or hide it.

Parameters:

val (bool)

Return type:

None

async set_discoverable_timeout(val)[source]

Set the discoverable timeout in seconds. A value of zero means that the timeout is disabled and it will stay in discoverable mode forever.

Parameters:

val (int)

Return type:

None

async set_pairable(val)[source]

Switch an adapter to pairable or non-pairable.

Parameters:

val (bool)

Return type:

None

async set_pairable_timeout(val)[source]

Set the pairable timeout in seconds. A value of zero means that the timeout is disabled and it will stay in pairable mode forever.

Parameters:

val (int)

Return type:

None

async set_powered(val)[source]

Turn this adapter on or off.

Parameters:

val (bool)

Return type:

None

async start_discovery()[source]

Start searching for other bluetooth devices.

Return type:

None

async stop_discovery()[source]

Stop searching for other bluetooth devices.

Return type:

None

class bluez_peripheral.adapter.Device(proxy)[source]

Bases: object

A bluetooth device discovered by an adapter. Represents an org.bluez.Device1 instance.

Parameters:

proxy (ProxyObject)

async get_alias()[source]

Returns the alias of this device.

Return type:

str

async get_appearance()[source]

Returns the appearance of the device.

Return type:

int

async get_manufacturer_data()[source]

Returns the manufacturer data.

Return type:

Dict[int, bytes]

async get_name()[source]

Returns the display name of this device (use alias instead to get the display name).

Return type:

str

async get_paired()[source]

Returns true if the parent adapter is paired with this device. False otherwise.

Return type:

bool

async get_service_data()[source]

Returns the service data.

Return type:

List[Tuple[str | bytes | UUID | UUID16 | int, bytes]]

async get_uuids()[source]

Returns the collection of UUIDs representing the services available on this device.

Return type:

Collection[str | bytes | UUID | UUID16 | int]

async pair()[source]

Attempts to pair the parent adapter with this device.

Return type:

None

async remove(adapter)[source]

Disconnects and unpairs from this device.

Parameters:

adapter (Adapter)

Return type:

None