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

Method _enrich_device_names

actions/ble.py:1035–1090  ·  view source on GitHub ↗

Enrich device information by querying bluetoothctl info for each device This gets better names, RSSI, and other details Args: devices: Dictionary of devices to enrich Returns: Enriched devices dictionary

(self, devices: Dict[str, Dict[str, Any]])

Source from the content-addressed store, hash-verified

1033 return details
1034
1035 def _enrich_device_names(self, devices: Dict[str, Dict[str, Any]]) -> Dict[str, Dict[str, Any]]:
1036 """
1037 Enrich device information by querying bluetoothctl info for each device
1038 This gets better names, RSSI, and other details
1039 Args:
1040 devices: Dictionary of devices to enrich
1041 Returns: Enriched devices dictionary
1042 """
1043 enriched_devices = devices.copy()
1044
1045 for address, device_info in enriched_devices.items():
1046 # Skip if we already have a good name (not Unknown/generic)
1047 current_name = device_info.get('name', '')
1048 if current_name and current_name not in ['Unknown Device', 'Unknown', '']:
1049 # Still try to get RSSI and other details if missing
1050 if device_info.get('rssi') is None:
1051 try:
1052 details = self._get_device_details(address)
1053 # Only update RSSI and other metadata, keep the name if it's good
1054 if 'rssi' in details:
1055 device_info['rssi'] = details['rssi']
1056 if 'device_class' in details and not device_info.get('device_class'):
1057 device_info['device_class'] = details['device_class']
1058 if 'device_type' in details and not device_info.get('device_type'):
1059 device_info['device_type'] = details['device_type']
1060 if 'paired' in details:
1061 device_info['paired'] = details['paired']
1062 if 'connected' in details:
1063 device_info['connected'] = details['connected']
1064 if 'trusted' in details:
1065 device_info['trusted'] = details['trusted']
1066 if 'services' in details and details['services']:
1067 device_info['services'] = details['services']
1068 except Exception as e:
1069 self.logger.debug(f"Could not enrich device {address}: {e}")
1070 continue
1071
1072 # Try to get full device details including proper name
1073 try:
1074 self.logger.debug(f"Enriching device info for {address}...")
1075 details = self._get_device_details(address)
1076
1077 if details:
1078 # Update with enriched information
1079 if 'name' in details:
1080 device_info['name'] = details['name']
1081 self.logger.info(f"Enriched name for {address}: {details['name']}")
1082
1083 # Update other fields
1084 for key in ['rssi', 'device_class', 'device_type', 'paired', 'connected', 'trusted', 'services', 'alias']:
1085 if key in details:
1086 device_info[key] = details[key]
1087 except Exception as e:
1088 self.logger.debug(f"Could not enrich device {address}: {e}")
1089
1090 return enriched_devices
1091
1092 def pair_device(self, address: str) -> Tuple[bool, str]:

Callers 1

Calls 6

_get_device_detailsMethod · 0.95
copyMethod · 0.80
debugMethod · 0.80
infoMethod · 0.80
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected