feat: assemble CAPABILITIES registry with duplicate-href guard
This commit is contained in:
1 parent
23d5090faa
commit
246379acbc
3 files changed
+38
-5
No files matched your search
@@ -0,0 +1,6 @@
|
||||
from .adapter import RuntimeDescriptor, build_runtime_descriptor
|
||||
from .discovery import BoundEntity, discover
|
||||
from .registry import CAPABILITIES
|
||||
|
||||
__all__ = ['CAPABILITIES', 'discover', 'BoundEntity',
|
||||
'RuntimeDescriptor', 'build_runtime_descriptor']
|
||||
@@ -3,11 +3,20 @@
|
||||
Built from the full list of Capability objects in the capabilities package.
|
||||
Consumed by discover() at connection time to bind device resources to entities.
|
||||
|
||||
Note: each href must appear in at most one Capability across all modules.
|
||||
If two capabilities share an href, the later one in the scan order wins —
|
||||
this is a bug, not a feature. Add all entities for a given href to the same
|
||||
Capability object instead.
|
||||
Raises ValueError at import if any href appears in multiple capabilities.
|
||||
"""
|
||||
from .capabilities import ALL
|
||||
from .capability import Capability
|
||||
|
||||
CAPABILITIES: dict = {cap.href: cap for cap in ALL}
|
||||
|
||||
def _build() -> dict[str, Capability]:
|
||||
"""Build the registry, raising ValueError if any href is duplicated."""
|
||||
out: dict[str, Capability] = {}
|
||||
for cap in ALL:
|
||||
if cap.href in out:
|
||||
raise ValueError(f"duplicate capability href: {cap.href}")
|
||||
out[cap.href] = cap
|
||||
return out
|
||||
|
||||
|
||||
CAPABILITIES: dict[str, Capability] = _build()
|
||||
Reference in new issue
Block a user