The DTLS/CoAP transport code that made "ocf" an accurate name moved out to the smartthings-local package. What's left here (capability.py, entities.py, discovery.py, adapter.py, identity.py, capabilities/, by_type/, plus the /device/0 batch parser) is entirely the device capability registry, so name the package for what it does. Flattened the redundant ocf/registry/ nesting into a single top-level registry/ package and updated every import across the platform modules and test suite accordingly. Verified: full test suite (80/80) passes, and the Docker dev container reconnects to both live appliances and rediscovers their entities cleanly after the rename.
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Global CAPABILITIES registry: href -> list[Capability].
|
|
|
|
Built from the full list of Capability objects in the capabilities package.
|
|
Consumed by discover() at connection time to bind device resources to entities.
|
|
|
|
Raises ValueError at import if any href group contains an unfiltered cap
|
|
alongside other caps (i.e., a cap with neither rt_filter nor match_fn set
|
|
in a group with multiple caps).
|
|
"""
|
|
from .capabilities import ALL
|
|
from .capability import Capability
|
|
|
|
|
|
def _build() -> dict[str, list[Capability]]:
|
|
"""Build the registry, raising ValueError for invalid duplicate hrefs.
|
|
|
|
Duplicates are allowed only when every cap in the group has at least one
|
|
of rt_filter or match_fn set. An unfiltered cap sharing an href with
|
|
another cap would be ambiguous.
|
|
|
|
Skips capabilities with href=None (pattern capabilities, handled elsewhere).
|
|
"""
|
|
out: dict[str, list[Capability]] = {}
|
|
for cap in ALL:
|
|
if cap.href is None:
|
|
continue
|
|
if cap.href not in out:
|
|
out[cap.href] = [cap]
|
|
else:
|
|
out[cap.href].append(cap)
|
|
|
|
# Validate: every group with >1 cap must have all caps filtered
|
|
for href, caps in out.items():
|
|
if len(caps) > 1:
|
|
unfiltered = [c for c in caps
|
|
if c.rt_filter is None and c.match_fn is None]
|
|
if unfiltered:
|
|
raise ValueError(
|
|
f"duplicate capability href {href!r} has unfiltered cap(s); "
|
|
f"each cap sharing an href must set rt_filter or match_fn"
|
|
)
|
|
|
|
return out
|
|
|
|
|
|
CAPABILITIES: dict[str, list[Capability]] = _build()
|