Coverage for src / bluetooth_sig / registry / uuids / object_types.py: 81%

31 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-11 20:14 +0000

1"""Object types registry for Bluetooth SIG object type definitions.""" 

2 

3# pylint: disable=duplicate-code 

4# NOTE: Registry classes intentionally follow the same pattern. 

5# This is by design for consistency across all UUID registries. 

6 

7from __future__ import annotations 

8 

9from bluetooth_sig.registry.base import BaseUUIDRegistry 

10from bluetooth_sig.types.registry.object_types import ObjectTypeInfo 

11from bluetooth_sig.types.uuid import BluetoothUUID 

12 

13 

14class ObjectTypesRegistry(BaseUUIDRegistry[ObjectTypeInfo]): 

15 """Registry for Bluetooth SIG Object Transfer Service (OTS) object types.""" 

16 

17 def _load_yaml_path(self) -> str: 

18 """Return the YAML file path relative to bluetooth_sig/ root.""" 

19 return "assigned_numbers/uuids/object_types.yaml" 

20 

21 def _create_info_from_yaml(self, uuid_data: dict[str, str], uuid: BluetoothUUID) -> ObjectTypeInfo: 

22 """Create ObjectTypeInfo from YAML data.""" 

23 return ObjectTypeInfo( 

24 uuid=uuid, 

25 name=uuid_data["name"], 

26 id=uuid_data["id"], 

27 ) 

28 

29 def _create_runtime_info(self, entry: object, uuid: BluetoothUUID) -> ObjectTypeInfo: 

30 """Create runtime ObjectTypeInfo from entry.""" 

31 return ObjectTypeInfo( 

32 uuid=uuid, 

33 name=getattr(entry, "name", ""), 

34 id=getattr(entry, "id", ""), 

35 ) 

36 

37 def get_object_type_info(self, uuid: str | BluetoothUUID) -> ObjectTypeInfo | None: 

38 """Get object type information by UUID. 

39 

40 Args: 

41 uuid: 16-bit UUID as string (with or without 0x) or BluetoothUUID 

42 

43 Returns: 

44 ObjectTypeInfo object, or None if not found 

45 """ 

46 return self.get_info(uuid) 

47 

48 def get_object_type_info_by_name(self, name: str) -> ObjectTypeInfo | None: 

49 """Get object type information by name. 

50 

51 Args: 

52 name: Object type name (case-insensitive) 

53 

54 Returns: 

55 ObjectTypeInfo object, or None if not found 

56 """ 

57 self._ensure_loaded() 

58 for info in self._canonical_store.values(): 

59 if info.name.lower() == name.lower(): 

60 return info 

61 return None 

62 

63 def get_object_type_info_by_id(self, object_type_id: str) -> ObjectTypeInfo | None: 

64 """Get object type information by ID. 

65 

66 Args: 

67 object_type_id: Object type ID (e.g., "org.bluetooth.object.track") 

68 

69 Returns: 

70 ObjectTypeInfo object, or None if not found 

71 """ 

72 self._ensure_loaded() 

73 for info in self._canonical_store.values(): 

74 if info.id == object_type_id: 

75 return info 

76 return None 

77 

78 def is_object_type_uuid(self, uuid: str | BluetoothUUID) -> bool: 

79 """Check if a UUID is a registered object type UUID. 

80 

81 Args: 

82 uuid: UUID to check 

83 

84 Returns: 

85 True if the UUID is an object type UUID, False otherwise 

86 """ 

87 return self.get_info(uuid) is not None 

88 

89 def get_all_object_types(self) -> list[ObjectTypeInfo]: 

90 """Get all registered object types. 

91 

92 Returns: 

93 List of all ObjectTypeInfo objects 

94 """ 

95 self._ensure_loaded() 

96 return list(self._canonical_store.values()) 

97 

98 

99# Global instance 

100object_types_registry = ObjectTypesRegistry.get_instance()