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

Method set_discoverable

actions/ble.py:271–299  ·  view source on GitHub ↗

Set Bluetooth discoverable mode Args: discoverable: True to make discoverable, False to hide Returns: (success, message)

(self, discoverable: bool)

Source from the content-addressed store, hash-verified

269 return False, f"Error disabling Bluetooth: {str(e)}"
270
271 def set_discoverable(self, discoverable: bool) -> Tuple[bool, str]:
272 """
273 Set Bluetooth discoverable mode
274 Args:
275 discoverable: True to make discoverable, False to hide
276 Returns: (success, message)
277 """
278 try:
279 mode = 'on' if discoverable else 'off'
280 action = 'discoverable' if discoverable else 'hidden'
281
282 self.logger.info(f"Setting Bluetooth {action}...")
283 result = subprocess.run(['bluetoothctl', 'discoverable', mode],
284 capture_output=True, text=True, timeout=10)
285
286 if result.returncode == 0:
287 message = f"Bluetooth is now {action}"
288 self.logger.info(message)
289 return True, message
290 else:
291 error_msg = result.stderr.strip() or f'Failed to make Bluetooth {action}'
292 self.logger.error(f"Failed to set discoverable mode: {error_msg}")
293 return False, error_msg
294
295 except subprocess.TimeoutExpired:
296 return False, "Discoverable command timed out"
297 except Exception as e:
298 self.logger.error(f"Error setting discoverable mode: {e}")
299 return False, f"Error setting discoverable mode: {str(e)}"
300
301 def start_scan(self, duration: Optional[int] = None) -> Tuple[bool, str]:
302 """

Callers 2

hide_bluetooth_deviceFunction · 0.80

Calls 3

infoMethod · 0.80
errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected