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

Method connect_device

actions/ble.py:1153–1177  ·  view source on GitHub ↗

Connect to a paired Bluetooth device Args: address: MAC address of the device to connect Returns: (success, message)

(self, address: str)

Source from the content-addressed store, hash-verified

1151 return False, f"Error removing device {address}: {str(e)}"
1152
1153 def connect_device(self, address: str) -> Tuple[bool, str]:
1154 """
1155 Connect to a paired Bluetooth device
1156 Args:
1157 address: MAC address of the device to connect
1158 Returns: (success, message)
1159 """
1160 try:
1161 self.logger.info(f"Connecting to device {address}...")
1162 result = subprocess.run(['bluetoothctl', 'connect', address],
1163 capture_output=True, text=True, timeout=20)
1164
1165 if result.returncode == 0 or 'Connection successful' in result.stdout:
1166 self.logger.info(f"Successfully connected to {address}")
1167 return True, f"Successfully connected to {address}"
1168 else:
1169 error_msg = result.stderr.strip() or f'Failed to connect to {address}'
1170 self.logger.error(f"Failed to connect to {address}: {error_msg}")
1171 return False, error_msg
1172
1173 except subprocess.TimeoutExpired:
1174 return False, f"Connection to {address} timed out"
1175 except Exception as e:
1176 self.logger.error(f"Error connecting to {address}: {e}")
1177 return False, f"Error connecting to {address}: {str(e)}"
1178
1179 def disconnect_device(self, address: str) -> Tuple[bool, str]:
1180 """

Callers

nothing calls this directly

Calls 3

infoMethod · 0.80
errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected