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:
@@ -4,12 +4,19 @@ import subprocess
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
|
|
||||||
from bleak import BleakScanner
|
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 .oui import OUILookup
|
||||||
from .bluetooth_class import BluetoothClassDecoder
|
from .bluetooth_class import BluetoothClassDecoder
|
||||||
from .distance import estimate_distance, rssi_to_quality, rssi_bar
|
from .distance import estimate_distance, rssi_to_quality, rssi_bar
|
||||||
@@ -184,7 +191,10 @@ class RFScanner:
|
|||||||
"""
|
"""
|
||||||
devices = []
|
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:
|
try:
|
||||||
print(f"Scanning Classic Bluetooth ({timeout} seconds)...")
|
print(f"Scanning Classic Bluetooth ({timeout} seconds)...")
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
@@ -217,7 +227,10 @@ class RFScanner:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Classic BT scan error: {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:
|
try:
|
||||||
print(f"Scanning BLE devices ({timeout} seconds)...")
|
print(f"Scanning BLE devices ({timeout} seconds)...")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user