Coverage for src / bluetooth_sig / registry / uuids / mesh_profiles.py: 84%
25 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 20:14 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 20:14 +0000
1"""Mesh profiles registry for Bluetooth SIG mesh profile definitions."""
3from __future__ import annotations
5from bluetooth_sig.registry.base import BaseUUIDRegistry
6from bluetooth_sig.types.registry.mesh_profile_uuids import MeshProfileInfo
7from bluetooth_sig.types.uuid import BluetoothUUID
10class MeshProfilesRegistry(BaseUUIDRegistry[MeshProfileInfo]):
11 """Registry for Bluetooth SIG mesh profile definitions."""
13 def _load_yaml_path(self) -> str:
14 """Return the YAML file path relative to bluetooth_sig/ root."""
15 return "assigned_numbers/uuids/mesh_profiles.yaml"
17 def _create_info_from_yaml(self, uuid_data: dict[str, str], uuid: BluetoothUUID) -> MeshProfileInfo:
18 """Create MeshProfileInfo from YAML data."""
19 return MeshProfileInfo(
20 uuid=uuid,
21 name=uuid_data["name"],
22 )
24 def _create_runtime_info(self, entry: object, uuid: BluetoothUUID) -> MeshProfileInfo:
25 """Create runtime MeshProfileInfo from entry."""
26 return MeshProfileInfo(
27 uuid=uuid,
28 name=getattr(entry, "name", ""),
29 )
31 def get_mesh_profile_info(self, uuid: str | BluetoothUUID) -> MeshProfileInfo | None:
32 """Get mesh profile information by UUID.
34 Args:
35 uuid: The UUID to look up (string, int, or BluetoothUUID)
37 Returns:
38 MeshProfileInfo if found, None otherwise
39 """
40 return self.get_info(uuid)
42 def get_mesh_profile_info_by_name(self, name: str) -> MeshProfileInfo | None:
43 """Get mesh profile information by name (case insensitive).
45 Args:
46 name: The mesh profile name to look up
48 Returns:
49 MeshProfileInfo if found, None otherwise
50 """
51 self._ensure_loaded()
52 for info in self._canonical_store.values():
53 if info.name.lower() == name.lower():
54 return info
55 return None
57 def is_mesh_profile_uuid(self, uuid: str | BluetoothUUID) -> bool:
58 """Check if a UUID corresponds to a known mesh profile.
60 Args:
61 uuid: The UUID to check
63 Returns:
64 True if the UUID is a known mesh profile, False otherwise
65 """
66 return self.get_info(uuid) is not None
68 def get_all_mesh_profiles(self) -> list[MeshProfileInfo]:
69 """Get all mesh profiles in the registry.
71 Returns:
72 List of all MeshProfileInfo objects
73 """
74 self._ensure_loaded()
75 return list(self._canonical_store.values())
78# Global instance for convenience
79mesh_profiles_registry = MeshProfilesRegistry.get_instance()