From fa8c44c0bf91beb3a1fb7b53f2ea72c1c22a9b82 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 21 Dec 2025 14:54:48 +0000 Subject: [PATCH] Fix bluetoothctl parsing - add missing imports and improve regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add missing time and re imports in stream function - Improve ANSI escape code stripping (add \x1b[K and \r removal) - Make MAC address regex more explicit - Add debug logging for Device lines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- intercept.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/intercept.py b/intercept.py index 10d54ea..f289920 100755 --- a/intercept.py +++ b/intercept.py @@ -5698,6 +5698,8 @@ def stream_bt_scan(process, scan_mode): # bluetoothctl scan output - read from pty import os import select + import time + import re master_fd = getattr(process, '_master_fd', None) if not master_fd: @@ -5721,15 +5723,21 @@ def stream_bt_scan(process, scan_mode): line = line.strip() # Remove ANSI escape codes - import re line = re.sub(r'\x1b\[[0-9;]*m', '', line) line = re.sub(r'\x1b\[\?.*?[a-zA-Z]', '', line) + line = re.sub(r'\x1b\[K', '', line) # Clear line escape + line = re.sub(r'\r', '', line) # Remove carriage returns + + # Debug: print what we're receiving + if line and 'Device' in line: + print(f"[BT] bluetoothctl: {line}") # Parse [NEW] Device or [CHG] Device lines - if 'Device' in line and ':' in line: - match = re.search(r'([0-9A-Fa-f:]{17})\s*(.*)', line) + # Format: [NEW] Device AA:BB:CC:DD:EE:FF DeviceName + if 'Device' in line: + match = re.search(r'([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})\s*(.*)', line) if match: - mac = match.group(1) + mac = match.group(1).upper() name = match.group(2).strip() device = {