bleak.backends.winrt package

Submodules

bleak.backends.winrt.characteristic module

class bleak.backends.winrt.characteristic.BleakGATTCharacteristicWinRT(obj: bleak_winrt.windows.devices.bluetooth.genericattributeprofile.GattCharacteristic, max_write_without_response_size: int)[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.descriptor.BleakGATTDescriptor]

List of descriptors for this characteristic

get_descriptor(specifier: Union[int, str, uuid.UUID]) Optional[bleak.backends.descriptor.BleakGATTDescriptor][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], *, winrt: bleak.backends.winrt.client.WinRTClientArgs, **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 (str or BLEDevice) – The Bluetooth address of the BLE peripheral to connect to or the BLEDevice object representing it.

  • winrt (dict) – A dictionary of Windows-specific configuration values.

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

  • **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.

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_level (int) –

A DevicePairingProtectionLevel enum value:

  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(characteristic: bleak.backends.characteristic.BleakGATTCharacteristic, callback: Callable[[bytearray], None], **kwargs) None[source]

Activate notifications/indications on a characteristic.

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.

class bleak.backends.winrt.client.WinRTClientArgs[source]

Bases: TypedDict

Windows-specific arguments for BleakClient.

address_type: Literal['public', 'random']

Can either be "public" or "random", depending on the required address type needed to connect to your device.

use_cached_services: bool

True allows Windows to fetch the services, characteristics and descriptors from the Windows cache instead of reading them from the device. Can be very much faster for known, unchanging devices, but not recommended for DIY peripherals where the GATT layout can change between connections.

False will force the attribute database to be read from the remote device instead of using the OS cache.

If omitted, the OS Bluetooth stack will do what it thinks is best.

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(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 native Windows Bleak BLE Scanner.

Implemented using Python/WinRT.

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.

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

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