MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _get_scan_results

Method _get_scan_results

actions/ble.py:657–875  ·  view source on GitHub ↗

Try to get devices discovered during active scanning using multiple methods This is a workaround since bluetoothctl devices might not show newly discovered devices

(self)

Source from the content-addressed store, hash-verified

655 return devices
656
657 def _get_scan_results(self) -> Dict[str, Dict[str, Any]]:
658 """
659 Try to get devices discovered during active scanning using multiple methods
660 This is a workaround since bluetoothctl devices might not show newly discovered devices
661 """
662 scan_devices = {}
663
664 # Method 1: Use bluetoothctl in batch mode with device listing
665 try:
666 # Start a fresh bluetoothctl session that scans and lists devices
667 ps_script = '''
668import subprocess
669import time
670import re
671
672devices = {}
673
674# Start bluetoothctl process
675proc = subprocess.Popen(
676 ['bluetoothctl'],
677 stdin=subprocess.PIPE,
678 stdout=subprocess.PIPE,
679 stderr=subprocess.PIPE,
680 text=True,
681 bufsize=1
682)
683
684# Send scan on command
685proc.stdin.write('scan on\\n')
686proc.stdin.flush()
687
688# Wait for devices to appear
689time.sleep(3)
690
691# Send devices command
692proc.stdin.write('devices\\n')
693proc.stdin.flush()
694time.sleep(0.5)
695
696# Send exit
697proc.stdin.write('exit\\n')
698proc.stdin.flush()
699
700# Read output
701try:
702 output, _ = proc.communicate(timeout=2)
703
704 # Parse device lines
705 for line in output.split('\\n'):
706 line = line.strip()
707 if line.startswith('Device '):
708 parts = line.split(None, 2)
709 if len(parts) >= 2:
710 addr = parts[1]
711 name = parts[2] if len(parts) > 2 else 'Unknown Device'
712 print(f"{addr}|{name}")
713except:
714 pass

Callers 1

Calls 3

infoMethod · 0.80
debugMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected