feat: assemble CAPABILITIES registry with duplicate-href guard

This commit is contained in:
Marc Billow
2026-06-30 16:32:37 -05:00
parent 23d5090faa
commit 246379acbc
3 changed files with 38 additions and 5 deletions
+6
View File
@@ -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']
+14 -5
View File
@@ -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()
+18
View File
@@ -0,0 +1,18 @@
"""Tests for the CAPABILITIES registry."""
from samsung_appliance.registry.registry import CAPABILITIES
def test_registry_is_keyed_by_href():
"""Registry keys should match capability hrefs."""
for href, cap in CAPABILITIES.items():
assert cap.href == href
def test_registry_has_no_duplicate_href():
"""Building succeeded => no duplicates raised at import."""
assert len(CAPABILITIES) >= 7
def test_operational_state_present():
"""At least one capability should have 'state' in its href."""
assert any('state' in href for href in CAPABILITIES)