bleak.backends.winrt package

Submodules

bleak.backends.winrt.characteristic module

class bleak.backends.winrt.characteristic.BleakGATTCharacteristicWinRT(obj: bleak_winrt.windows.devices.bluetooth.genericattributeprofile.GattCharacteristicProperties)[source]

Bases: bleak.backends.characteristic.BleakGATTCharacteristic

GATT Characteristic implementation for the .NET backend, implemented with WinRT

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 description: str

Description for this characteristic

property descriptors: List[bleak.backends.winrt.descriptor.BleakGATTDescriptorWinRT]

List of descriptors for this service

get_descriptor(specifier: Union[int, str, uuid.UUID]) Optional[bleak.backends.winrt.descriptor.BleakGATTDescriptorWinRT][source]

Get a descriptor by handle (int) or UUID (str or uuid.UUID)

property handle: int

The handle of this characteristic

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.winrt.client module

BLE Client for Windows 10 systems, implemented with WinRT.

Created on 2020-08-19 by hbldh <henrik.blidh@nedomkull.com>

class bleak.backends.winrt.client.BleakClientWinRT(address_or_ble_device: Union[bleak.backends.device.BLEDevice, str], **kwargs)[source]

Bases: bleak.backends.client.BaseBleakClient

Native Windows Bleak Client.

Implemented using winrt, a package that enables Python developers to access Windows Runtime APIs directly from Python.

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

timeout (float) – Timeout for required BleakScanner.find_device_by_address call. Defaults to 10.0.

async connect(**kwargs) bool[source]

Connect to the specified GATT server.

Keyword Arguments

timeout (float) – Timeout for required BleakScanner.find_device_by_address call. Defaults to 10.0.

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(**kwargs) 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: int

Get ATT MTU size for active connection

async pair(protection_level: Optional[int] = None, **kwargs) bool[source]

Attempts to pair with the device.

Keyword Arguments

protection_levelWindows.Devices.Enumeration.DevicePairingProtectionLevel 1: None - Pair the device using no levels of protection. 2: Encryption - Pair the device using encryption. 3: EncryptionAndAuthentication - Pair the device using encryption and authentication. (This will not work in Bleak…)

Returns

Boolean regarding success of pairing.

async read_gatt_char(char_specifier: Union[bleak.backends.characteristic.BleakGATTCharacteristic, int, str, uuid.UUID], **kwargs) bytearray[source]

Perform read operation on the specified GATT characteristic.

Parameters

char_specifier (BleakGATTCharacteristic, int, str or UUID) – The characteristic to read from, specified by either integer handle, UUID or directly by the BleakGATTCharacteristic object representing it.

Keyword Arguments

use_cached (bool) – False forces Windows to read the value from the device again and not use its own cached value. Defaults to False.

Returns

(bytearray) The read data.

async read_gatt_descriptor(handle: int, **kwargs) bytearray[source]

Perform read operation on the specified GATT descriptor.

Parameters

handle (int) – The handle of the descriptor to read from.

Keyword Arguments

use_cached (bool) – False forces Windows to read the value from the device again and not use its own cached value. Defaults to False.

Returns

(bytearray) The read data.

async start_notify(char_specifier: Union[bleak.backends.characteristic.BleakGATTCharacteristic, int, str, uuid.UUID], callback: Callable[[int, bytearray], None], **kwargs) None[source]

Activate notifications/indications on a characteristic.

Callbacks must accept two inputs. The first will be a uuid string object and the second will be a bytearray.

def callback(sender, data):
    print(f"{sender}: {data}")
client.start_notify(char_uuid, callback)
Parameters
  • char_specifier (BleakGATTCharacteristic, int, str or UUID) – The characteristic to activate notifications/indications on a characteristic, specified by either integer handle, UUID or directly by the BleakGATTCharacteristic object representing it.

  • callback (function) – The function to be called on notification.

Keyword Arguments

force_indicate (bool) – If this is set to True, then Bleak will set up a indication request instead of a notification request, given that the characteristic supports notifications as well as indications.

async stop_notify(char_specifier: Union[bleak.backends.characteristic.BleakGATTCharacteristic, int, str, uuid.UUID]) None[source]

Deactivate notification/indication on a specified characteristic.

Parameters

char_specifier (BleakGATTCharacteristic, int, str or UUID) – The characteristic to deactivate notification/indication on, specified by either integer handle, UUID or directly by the BleakGATTCharacteristic object representing it.

async unpair() bool[source]

Attempts to unpair from the device.

N.B. unpairing also leads to disconnection in the Windows backend.

Returns

Boolean on whether the unparing was successful.

async write_gatt_char(char_specifier: Union[bleak.backends.characteristic.BleakGATTCharacteristic, int, str, uuid.UUID], data: Union[bytes, bytearray, memoryview], response: bool = False) None[source]

Perform a write operation of the specified GATT characteristic.

Parameters
  • char_specifier (BleakGATTCharacteristic, int, str or UUID) – The characteristic to write to, specified by either integer handle, UUID or directly by the BleakGATTCharacteristic 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(handle: int, data: Union[bytes, bytearray, memoryview]) None[source]

Perform a write operation on the specified GATT descriptor.

Parameters
  • handle (int) – The handle of the descriptor to read from.

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

bleak.backends.winrt.descriptor module

class bleak.backends.winrt.descriptor.BleakGATTDescriptorWinRT(obj: bleak_winrt.windows.devices.bluetooth.genericattributeprofile.GattDescriptor, characteristic_uuid: str, characteristic_handle: int)[source]

Bases: bleak.backends.descriptor.BleakGATTDescriptor

GATT Descriptor implementation for .NET backend, implemented with WinRT

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.winrt.scanner module

class bleak.backends.winrt.scanner.BleakScannerWinRT(**kwargs)[source]

Bases: bleak.backends.scanner.BaseBleakScanner

The native Windows Bleak BLE Scanner.

Implemented using Python/WinRT.

Keyword Arguments

mode (scanning) – Set to “Passive” to avoid the “Active” scanning mode.

property discovered_devices: List[bleak.backends.device.BLEDevice]

Gets the devices registered by the BleakScanner.

Returns

A list of the devices that the scanner has discovered during the scanning.

set_scanning_filter(**kwargs)[source]

Set a scanning filter for the BleakScanner.

Keyword Arguments
  • SignalStrengthFilter (Windows.Devices.Bluetooth.BluetoothSignalStrengthFilter) – A BluetoothSignalStrengthFilter object used for configuration of Bluetooth LE advertisement filtering that uses signal strength-based filtering.

  • AdvertisementFilter (Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementFilter) – A BluetoothLEAdvertisementFilter object used for configuration of Bluetooth LE advertisement filtering that uses payload section-based filtering.

async start()[source]

Start scanning for devices

async stop()[source]

Stop scanning for devices

bleak.backends.winrt.service module

class bleak.backends.winrt.service.BleakGATTServiceWinRT(obj: bleak_winrt.windows.devices.bluetooth.genericattributeprofile.GattDeviceService)[source]

Bases: bleak.backends.service.BleakGATTService

GATT Characteristic implementation for the .NET backend, implemented with WinRT

add_characteristic(characteristic: bleak.backends.winrt.characteristic.BleakGATTCharacteristicWinRT)[source]

Add a BleakGATTCharacteristicWinRT to the service.

Should not be used by end user, but rather by bleak itself.

property characteristics: List[bleak.backends.winrt.characteristic.BleakGATTCharacteristicWinRT]

List of characteristics for this service

property handle: int

The handle of this service

property uuid: str

The UUID to this service

Module contents