bleak.backends.p4android package
Submodules
bleak.backends.p4android.characteristic module
- class bleak.backends.p4android.characteristic.BleakGATTCharacteristicP4Android(java, service_uuid: str, service_handle: int, max_write_without_response_size: int)[source]
Bases:
bleak.backends.characteristic.BleakGATTCharacteristic
GATT Characteristic implementation for the python-for-android backend
- add_descriptor(descriptor: bleak.backends.descriptor.BleakGATTDescriptor)[source]
Add a
BleakGATTDescriptor
to the characteristic.Should not be used by end user, but rather by bleak itself.
- property descriptors: List[bleak.backends.descriptor.BleakGATTDescriptor]
List of descriptors for this service
- get_descriptor(specifier: Union[str, uuid.UUID]) Optional[bleak.backends.descriptor.BleakGATTDescriptor] [source]
Get a descriptor by UUID (str or uuid.UUID)
- property handle: int
The handle of this characteristic
- property notification_descriptor: bleak.backends.descriptor.BleakGATTDescriptor
The notification descriptor. Mostly needed by bleak, not by end user
- property properties: List[str]
Properties of this characteristic
- property service_handle: int
The integer handle of the Service containing this characteristic
- property service_uuid: str
The uuid of the Service containing this characteristic
- property uuid: str
The uuid of this characteristic
bleak.backends.p4android.client module
BLE Client for python-for-android
- class bleak.backends.p4android.client.BleakClientP4Android(address_or_ble_device: Union[bleak.backends.device.BLEDevice, str], **kwargs)[source]
Bases:
bleak.backends.client.BaseBleakClient
A python-for-android Bleak Client
- Parameters
address_or_ble_device (BLEDevice or str) – The Bluetooth address of the BLE peripheral to connect to or the BLEDevice object representing it.
- Keyword Arguments
disconnected_callback (callable) – Callback that will be scheduled in the event loop when the client is disconnected. The callable must take one argument, which will be this client object.
adapter (str) – Bluetooth adapter to use for discovery. [unused]
- async connect(**kwargs) bool [source]
Connect to the specified GATT server.
- Returns
Boolean representing connection status.
- async disconnect() bool [source]
Disconnect from the specified GATT server.
- Returns
Boolean representing if device is disconnected.
- async get_services() bleak.backends.service.BleakGATTServiceCollection [source]
Get all services registered for this GATT server.
- Returns
A
bleak.backends.service.BleakGATTServiceCollection
with this device’s services tree.
- property is_connected: bool
Check connection status between this client and the server.
- Returns
Boolean representing connection status.
- property mtu_size: Optional[int]
Gets the negotiated MTU.
- async pair(*args, **kwargs) bool [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.
- Returns
Boolean regarding success of pairing.
- async read_gatt_char(char_specifier: Union[bleak.backends.p4android.characteristic.BleakGATTCharacteristicP4Android, int, str, uuid.UUID], **kwargs) bytearray [source]
Perform read operation on the specified GATT characteristic.
- Parameters
char_specifier (BleakGATTCharacteristicP4Android, int, str or UUID) – The characteristic to read from, specified by either integer handle, UUID or directly by the BleakGATTCharacteristicP4Android object representing it.
- Returns
(bytearray) The read data.
- async read_gatt_descriptor(desc_specifier: Union[bleak.backends.p4android.descriptor.BleakGATTDescriptorP4Android, str, uuid.UUID], **kwargs) bytearray [source]
Perform read operation on the specified GATT descriptor.
- Parameters
desc_specifier (BleakGATTDescriptorP4Android, str or UUID) – The descriptor to read from, specified by either UUID or directly by the BleakGATTDescriptorP4Android object representing it.
- Returns
(bytearray) The read data.
- async start_notify(characteristic: bleak.backends.characteristic.BleakGATTCharacteristic, callback: Callable[[bytearray], None], **kwargs) None [source]
Activate notifications/indications on a characteristic.
- async stop_notify(char_specifier: Union[bleak.backends.p4android.characteristic.BleakGATTCharacteristicP4Android, int, str, uuid.UUID]) None [source]
Deactivate notification/indication on a specified characteristic.
- Parameters
char_specifier (BleakGATTCharacteristicP4Android, int, str or UUID) – The characteristic to deactivate notification/indication on, specified by either integer handle, UUID or directly by the BleakGATTCharacteristicP4Android object representing it.
- async unpair() bool [source]
Unpair with the peripheral.
- Returns
Boolean regarding success of unpairing.
- async write_gatt_char(char_specifier: Union[bleak.backends.p4android.characteristic.BleakGATTCharacteristicP4Android, int, str, uuid.UUID], data: bytearray, response: bool = False) None [source]
Perform a write operation on the specified GATT characteristic.
- Parameters
char_specifier (BleakGATTCharacteristicP4Android, int, str or UUID) – The characteristic to write to, specified by either integer handle, UUID or directly by the BleakGATTCharacteristicP4Android object representing it.
data (bytes or bytearray) – The data to send.
response (bool) – If write-with-response operation should be done. Defaults to False.
- async write_gatt_descriptor(desc_specifier: Union[bleak.backends.p4android.descriptor.BleakGATTDescriptorP4Android, str, uuid.UUID], data: bytearray) None [source]
Perform a write operation on the specified GATT descriptor.
- Parameters
desc_specifier (BleakGATTDescriptorP4Android, str or UUID) – The descriptor to write to, specified by either UUID or directly by the BleakGATTDescriptorP4Android object representing it.
data (bytes or bytearray) – The data to send.
bleak.backends.p4android.defs module
bleak.backends.p4android.descriptor module
- class bleak.backends.p4android.descriptor.BleakGATTDescriptorP4Android(java, characteristic_uuid: str, characteristic_handle: int, index: int)[source]
Bases:
bleak.backends.descriptor.BleakGATTDescriptor
GATT Descriptor implementation for python-for-android backend
- property characteristic_handle: int
handle for the characteristic that this descriptor belongs to
- property characteristic_uuid: str
UUID for the characteristic that this descriptor belongs to
- property handle: int
Integer handle for this descriptor
- property uuid: str
UUID for this descriptor
bleak.backends.p4android.scanner module
- class bleak.backends.p4android.scanner.BleakScannerP4Android(detection_callback: Optional[Callable[[bleak.backends.device.BLEDevice, bleak.backends.scanner.AdvertisementData], Optional[Awaitable[None]]]], service_uuids: Optional[List[str]], scanning_mode: Literal['active', 'passive'], **kwargs)[source]
Bases:
bleak.backends.scanner.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.
bleak.backends.p4android.service module
- class bleak.backends.p4android.service.BleakGATTServiceP4Android(java)[source]
Bases:
bleak.backends.service.BleakGATTService
GATT Service implementation for the python-for-android backend
- add_characteristic(characteristic: bleak.backends.p4android.characteristic.BleakGATTCharacteristicP4Android)[source]
Add a
BleakGATTCharacteristicP4Android
to the service.Should not be used by end user, but rather by bleak itself.
- property characteristics: List[bleak.backends.p4android.characteristic.BleakGATTCharacteristicP4Android]
List of characteristics for this service
- property handle: int
A unique identifier for this service
- property uuid: str
The UUID to this service