fix: skip Bluetooth scanning on Termux/Android

Bleak requires D-Bus which isn't available on Android. Detect Termux
environment and skip both Classic BT and BLE scanning gracefully.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
User
2026-02-01 13:52:23 +01:00
parent b0e6d1107c
commit 3ff43de5ea
+15 -2
View File
@@ -4,12 +4,19 @@ import subprocess
import re
import json
import asyncio
import os
from datetime import datetime
from pathlib import Path
from dataclasses import dataclass, asdict
from bleak import BleakScanner
def is_termux() -> bool:
"""Detect if running in Termux (Android)."""
return os.environ.get('TERMUX_VERSION') is not None or \
os.path.exists('/data/data/com.termux')
from .oui import OUILookup
from .bluetooth_class import BluetoothClassDecoder
from .distance import estimate_distance, rssi_to_quality, rssi_bar
@@ -184,7 +191,10 @@ class RFScanner:
"""
devices = []
# Classic Bluetooth scan
# Classic Bluetooth scan (not supported on Termux/Android)
if is_termux():
print("Skipping Classic BT scan (not supported on Termux)")
else:
try:
print(f"Scanning Classic Bluetooth ({timeout} seconds)...")
result = subprocess.run(
@@ -217,7 +227,10 @@ class RFScanner:
except Exception as e:
print(f"Classic BT scan error: {e}")
# BLE scan using bleak
# BLE scan using bleak (not supported on Termux/Android)
if is_termux():
print("Skipping BLE scan (not supported on Termux)")
else:
try:
print(f"Scanning BLE devices ({timeout} seconds)...")