Bluetooth Auto Recovery

1.5.3 · active · verified Thu Apr 16

bluetooth-auto-recovery is a Python library designed to detect and recover Bluetooth adapters that enter an unresponsive or 'stuck' state. It actively monitors Bluetooth management sockets and initiates recovery procedures, such as resetting the adapter, when issues are detected. The current version is 1.5.3, with minor releases focusing on bug fixes and dependency updates, typically every few months.

Common errors

Warnings

Install

Imports

Quickstart

Initializes `BluetoothAutoRecovery` and starts monitoring Bluetooth adapters in an asynchronous context. The recovery process runs in the background, attempting to fix unresponsive adapters. This example includes a robust shutdown on `KeyboardInterrupt`.

import asyncio
from bluetooth_auto_recovery import BluetoothAutoRecovery

async def main():
    print("Starting Bluetooth Auto Recovery...")
    async with BluetoothAutoRecovery(
        recovery_timeout=60, # Max time to wait for recovery in seconds
        unresponsive_timeout=300 # Time to wait for unresponsiveness before recovering
    ) as recovery:
        print("Monitoring Bluetooth adapters. Press Ctrl+C to stop.")
        try:
            # Start monitoring in the background
            await recovery.start()
            # Keep the main task running indefinitely to monitor
            await asyncio.Future() # Await an eternal future
        except asyncio.CancelledError:
            print("Monitoring stopped.")
        finally:
            await recovery.stop() # Explicitly stop the recovery
            print("Bluetooth Auto Recovery stopped.")

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("Program interrupted by user.")

view raw JSON →