bleak.backends.p4android package

Submodules

bleak.backends.p4android.client module

BLE Client for python-for-android

class bleak.backends.p4android.client.BleakClientP4Android(address_or_ble_device: BLEDevice | str, services: set[UUID] | None, **kwargs)[source]

Bases: BaseBleakClient

A python-for-android Bleak Client

Parameters:
  • address_or_ble_device – The Bluetooth address of the BLE peripheral to connect to or the BLEDevice object representing it.

  • services – Optional set of services UUIDs to filter.

async connect(pair: bool, **kwargs) None[source]

Connect to the specified GATT server.

async disconnect() None[source]

Disconnect from the specified GATT server.

property is_connected: bool

Check connection status between this client and the server.

Returns:

Boolean representing connection status.

property mtu_size: int

Gets the negotiated MTU.

async pair(*args, **kwargs) None[source]

Pair with the peripheral.

You can use ConnectDevice method if you already know the MAC address of the device. Else you need to StartDiscovery, Trust, Pair and Connect in sequence.

async read_gatt_char(characteristic: BleakGATTCharacteristic, **kwargs: Any) bytearray[source]

Perform read operation on the specified GATT characteristic.

Parameters:

characteristic (BleakGATTCharacteristic) – The characteristic to read from.

Returns:

(bytearray) The read data.

async read_gatt_descriptor(descriptor: BleakGATTDescriptor, **kwargs: Any) bytearray[source]

Perform read operation on the specified GATT descriptor.

Parameters:

descriptor – The descriptor to read from.

Returns:

The read data.

async start_notify(characteristic: BleakGATTCharacteristic, callback: Callable[[bytearray], None], **kwargs) None[source]

Activate notifications/indications on a characteristic.

async stop_notify(characteristic: BleakGATTCharacteristic) None[source]

Deactivate notification/indication on a specified characteristic.

Parameters:

characteristic (BleakGATTCharacteristic) – The characteristic to deactivate notification/indication on,.

async unpair() None[source]

Unpair with the peripheral.

async write_gatt_char(characteristic: BleakGATTCharacteristic, data: bytearray, response: bool) None[source]

Perform a write operation on the specified GATT characteristic.

Parameters:
  • characteristic – The characteristic to write to.

  • data – The data to send.

  • response – If write-with-response operation should be done.

async write_gatt_descriptor(desc_specifier: BleakGATTDescriptor | str | UUID, data: bytearray) None[source]

Perform a write operation on the specified GATT descriptor.

Parameters:
  • desc_specifier (BleakGATTDescriptor, str or UUID) – The descriptor to write to, specified by either UUID or directly by the BleakGATTDescriptor object representing it.

  • data (bytes or bytearray) – The data to send.

bleak.backends.p4android.defs module

class bleak.backends.p4android.defs.ScanFailed(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

bleak.backends.p4android.scanner module

class bleak.backends.p4android.scanner.BleakScannerP4Android(detection_callback: Callable[[BLEDevice, AdvertisementData], Coroutine[Any, Any, None] | None] | None, service_uuids: list[str] | None, scanning_mode: Literal['active', 'passive'], **kwargs)[source]

Bases: BaseBleakScanner

The python-for-android Bleak BLE Scanner.

Parameters:
  • detection_callback – Optional function that will be called each time a device is discovered or advertising data has changed.

  • service_uuids – Optional list of service UUIDs to filter on. Only advertisements containing this advertising data will be received. Specifying this also enables scanning while the screen is off on Android.

  • scanning_mode – Set to "passive" to avoid the "active" scanning mode.

async start() None[source]

Start scanning for devices

async stop() None[source]

Stop scanning for devices

bleak.backends.p4android.utils module

class bleak.backends.p4android.utils.AsyncJavaCallbacks(*args: Any, **kwargs: Any)[source]

Bases: PythonJavaClass

async perform_and_wait(dispatchApi, dispatchParams, resultApi, resultExpected=(), unless_already=False, return_indicates_status=True)[source]

Module contents