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:
BleakGATTCharacteristic
GATT Characteristic implementation for the python-for-android backend
- add_descriptor(descriptor: BleakGATTDescriptor)[source]
Add a
BleakGATTDescriptor
to the characteristic.Should not be used by end user, but rather by bleak itself.
- property descriptors: List[BleakGATTDescriptor]
List of descriptors for this service
- get_descriptor(specifier: Union[str, UUID]) Optional[BleakGATTDescriptor] [source]
Get a descriptor by UUID (str or uuid.UUID)
- property handle: int
The handle of this characteristic
- property notification_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[BLEDevice, str], services: Optional[Set[UUID]], **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(**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() 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[BleakGATTCharacteristicP4Android, int, str, 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[BleakGATTDescriptorP4Android, str, 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: BleakGATTCharacteristic, callback: Callable[[bytearray], None], **kwargs) None [source]
Activate notifications/indications on a characteristic.
- async stop_notify(char_specifier: Union[BleakGATTCharacteristicP4Android, int, str, 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[BleakGATTCharacteristicP4Android, int, str, 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[BleakGATTDescriptorP4Android, str, 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:
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[[BLEDevice, AdvertisementData], Optional[Awaitable[None]]]], service_uuids: Optional[List[str]], 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.
bleak.backends.p4android.service module
- class bleak.backends.p4android.service.BleakGATTServiceP4Android(java)[source]
Bases:
BleakGATTService
GATT Service implementation for the python-for-android backend
- add_characteristic(characteristic: BleakGATTCharacteristicP4Android)[source]
Add a
BleakGATTCharacteristicP4Android
to the service.Should not be used by end user, but rather by bleak itself.
- property characteristics: List[BleakGATTCharacteristicP4Android]
List of characteristics for this service
- property handle: int
A unique identifier for this service
- property uuid: str
The UUID to this service