Fallback scan using bluetoothctl directly.
(self, adapter: str)
| 2091 | } |
| 2092 | |
| 2093 | def _bluetooth_scanner_fallback(self, adapter: str): |
| 2094 | """Fallback scan using bluetoothctl directly.""" |
| 2095 | mode = 'bluetooth' |
| 2096 | stop_event = self.stop_events.get(mode) |
| 2097 | |
| 2098 | try: |
| 2099 | proc = subprocess.Popen( |
| 2100 | ['bluetoothctl'], |
| 2101 | stdin=subprocess.PIPE, |
| 2102 | stdout=subprocess.PIPE, |
| 2103 | stderr=subprocess.PIPE, |
| 2104 | ) |
| 2105 | self.processes['bluetooth'] = proc |
| 2106 | |
| 2107 | proc.stdin.write(b'scan on\n') |
| 2108 | proc.stdin.flush() |
| 2109 | |
| 2110 | while not (stop_event and stop_event.is_set()): |
| 2111 | line = proc.stdout.readline() |
| 2112 | if not line: |
| 2113 | break |
| 2114 | |
| 2115 | line = line.decode('utf-8', errors='replace').strip() |
| 2116 | if 'Device' in line: |
| 2117 | self._parse_bluetooth_line(line) |
| 2118 | |
| 2119 | time.sleep(0.1) |
| 2120 | |
| 2121 | proc.stdin.write(b'scan off\n') |
| 2122 | proc.stdin.write(b'exit\n') |
| 2123 | proc.stdin.flush() |
| 2124 | proc.wait(timeout=2) |
| 2125 | |
| 2126 | except Exception as e: |
| 2127 | logger.error(f"Bluetooth scanner error: {e}") |
| 2128 | finally: |
| 2129 | logger.info("Bluetooth scanner stopped") |
| 2130 | |
| 2131 | def _parse_bluetooth_line(self, line: str): |
| 2132 | """Parse bluetoothctl output line.""" |
nothing calls this directly
no test coverage detected