CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-bleak

Cross-platform Bluetooth Low Energy GATT client library for asynchronous BLE communication

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-2/

BLE Connection Manager

A utility module for managing Bluetooth Low Energy device connections with proper connection lifecycle management, including connection status tracking and graceful disconnection.

Capabilities

Establish and Verify Connection

  • Connect to a BLE device using a device address and verify the connection is established @test
  • Check connection status after successfully connecting returns True @test

Disconnect from Device

  • Disconnect from a connected BLE device and verify disconnection completes successfully @test
  • Check connection status after disconnecting returns False @test

Async Context Manager Usage

  • Connect and disconnect automatically using async context manager @test
  • Connection status is False after exiting async context manager @test

Implementation

@generates

API

from bleak import BleakClient

class BLEConnectionManager:
    """Manages BLE device connections with proper lifecycle handling."""

    def __init__(self, device_address: str):
        """
        Initialize the BLE connection manager.

        Args:
            device_address: Bluetooth address of the device to connect to
        """
        pass

    async def connect(self) -> None:
        """
        Connect to the BLE device.

        Raises:
            Exception: If connection fails
        """
        pass

    async def disconnect(self) -> None:
        """
        Disconnect from the BLE device if connected.
        """
        pass

    def is_connected(self) -> bool:
        """
        Check if currently connected to the device.

        Returns:
            True if connected, False otherwise
        """
        pass

    async def __aenter__(self):
        """Async context manager entry - connects to device."""
        pass

    async def __aexit__(self, exc_type, exc_val, exc_tb):
        """Async context manager exit - disconnects from device."""
        pass

Dependencies { .dependencies }

bleak { .dependency }

Provides Bluetooth Low Energy GATT client functionality for connecting to and communicating with BLE devices.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-bleak

tile.json