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 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
¶ The handle of this characteristic
-
property
notification_descriptor
¶ The notification descriptor. Mostly needed by bleak, not by end user
-
property
properties
¶ Properties of this characteristic
-
property
service_handle
¶ The integer handle of the Service containing this characteristic
-
property
service_uuid
¶ The uuid of the Service containing this characteristic
-
property
uuid
¶ 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], services: Optional[Set[uuid.UUID]], **kwargs)[source]¶ Bases:
bleak.backends.client.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
() → 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
¶ Check connection status between this client and the server.
- Returns
Boolean representing connection status.
-
property
mtu_size
¶ 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
¶ handle for the characteristic that this descriptor belongs to
-
property
characteristic_uuid
¶ UUID for the characteristic that this descriptor belongs to
-
property
handle
¶ Integer handle for this descriptor
-
property
uuid
¶ UUID for this descriptor
-
property
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.
-
seen_devices
: Dict[str, Tuple[bleak.backends.device.BLEDevice, bleak.backends.scanner.AdvertisementData]]¶ Map of device identifier to BLEDevice and most recent advertisement data.
This map must be cleared when scanning starts.
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 of characteristics for this service
-
property
handle
¶ A unique identifier for this service
-
property
uuid
¶ The UUID to this service
-