diff --git a/samsung_appliance/registry/__init__.py b/samsung_appliance/registry/__init__.py index e69de29..f1045d1 100644 --- a/samsung_appliance/registry/__init__.py +++ b/samsung_appliance/registry/__init__.py @@ -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'] diff --git a/samsung_appliance/registry/registry.py b/samsung_appliance/registry/registry.py index af5a5b1..5310c54 100644 --- a/samsung_appliance/registry/registry.py +++ b/samsung_appliance/registry/registry.py @@ -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() diff --git a/tests/test_registry.py b/tests/test_registry.py new file mode 100644 index 0000000..5b88cb1 --- /dev/null +++ b/tests/test_registry.py @@ -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)