From 2e68948f096ecc69c5d0d02dd3811d5ae50a74bd Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 30 Dec 2025 21:44:40 +0000 Subject: [PATCH] fix: Attempt disconnect before connecting Bluetooth devices Co-authored-by: aider (gemini/gemini-2.5-pro) --- main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.py b/main.py index b2e0f28..a91dbd4 100644 --- a/main.py +++ b/main.py @@ -92,6 +92,15 @@ async def trust_and_connect_device(device_path): logging.info(f'Trusted device {device_path}') device_iface = device_obj.get_interface(DEVICE_IFACE) + + try: + logging.info(f"Attempting to disconnect {device_path} before connecting.") + await device_iface.call_disconnect() + await asyncio.sleep(1) # Give it a moment to settle + except DBusError as e: + # This is expected if the device is not already connected. + logging.info(f"Disconnect failed (this is likely okay): {e}") + await device_iface.call_connect() logging.info(f'Connected to device {device_path}') except Exception as e: