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

Method scan_for_time

actions/ble.py:1247–1283  ·  view source on GitHub ↗

Perform a timed Bluetooth scan Args: duration: Scan duration in seconds Returns: Dictionary of discovered devices

(self, duration: int)

Source from the content-addressed store, hash-verified

1245 return paired_devices
1246
1247 def scan_for_time(self, duration: int) -> Dict[str, Dict[str, Any]]:
1248 """
1249 Perform a timed Bluetooth scan
1250 Args:
1251 duration: Scan duration in seconds
1252 Returns: Dictionary of discovered devices
1253 """
1254 self.logger.info(f"Starting {duration}-second Bluetooth scan...")
1255
1256 if self._is_linux():
1257 # On Linux/Raspberry Pi, use an interactive approach that captures real-time discoveries
1258 try:
1259 devices = self._linux_interactive_scan(duration)
1260 if devices:
1261 self.logger.info(f"Interactive scan found {len(devices)} devices")
1262 return devices
1263 except Exception as e:
1264 self.logger.warning(f"Interactive scan failed: {e}, falling back to standard method")
1265
1266 # Fallback to standard method
1267 # Start scan
1268 success, message = self.start_scan()
1269 if not success:
1270 self.logger.error(f"Failed to start scan: {message}")
1271 return {}
1272
1273 # Wait for specified duration
1274 time.sleep(duration)
1275
1276 # Get discovered devices
1277 devices = self.get_discovered_devices()
1278
1279 # Stop scan
1280 self.stop_scan()
1281
1282 self.logger.info(f"Scan completed. Found {len(devices)} devices.")
1283 return devices
1284
1285 def _linux_interactive_scan(self, duration: int) -> Dict[str, Dict[str, Any]]:
1286 """

Callers 3

quick_scanFunction · 0.95
executeMethod · 0.80
ble.pyFile · 0.80

Calls 9

_is_linuxMethod · 0.95
start_scanMethod · 0.95
stop_scanMethod · 0.95
infoMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
sleepMethod · 0.45

Tested by

no test coverage detected