refactor: auto-derive pattern cap keys from href; move dumps to tests/fixtures

Remove key_fn from Capability — pattern cap keys are now always derived
automatically: strip digits from href segments, join with '_', append
'_' + desc.key. /door/cooler/0 + 'open' -> door_cooler_open.

DOOR_GENERIC entity key: 'open' (not 'door_open'). Remove _door_key helper.
Fridge registry: DOOR_FRIDGE/DOOR_FREEZER replaced by DOOR_GENERIC pattern cap.
Golden baseline: door_fridge_open -> door_cooler_open.

Move device dumps to tests/fixtures/dumps/ (tracked) so tests run in CI
without local-tools/ dependencies.
This commit is contained in:
Marc Billow committed 2026-06-30 16:33:36 -05:00
1 parent 1c4cb2e272
commit 27d6d09fd9
11 files changed
+37 -51

No files matched your search

@@ -15,8 +15,6 @@ REGISTRY = DeviceRegistry(
fridge.TEMP_FREEZER_CURRENT,
fridge.TEMP_FRIDGE_SETPOINT,
fridge.TEMP_FREEZER_SETPOINT,
fridge.DOOR_FRIDGE,
fridge.DOOR_FREEZER,
fridge.DOORS_STATUS,
fridge.ICEMAKER_ONE,
fridge.ICEMAKER_TWO,
@@ -345,19 +345,12 @@ FIRMWARE_UPDATE = Capability(
# Generic door pattern capability (href=None — use as pattern_cap only)
# ---------------------------------------------------------------------------
def _door_key(href: str) -> str:
# /door/cooler/0 -> door_cooler_open ; /door/wine/0 -> door_wine_open
segs = [s for s in href.strip('/').split('/') if s and not s.isdigit()]
return '_'.join(segs) + '_open'
DOOR_GENERIC = Capability(
href=None,
href_prefix='/door/',
poll_tier='hot',
key_fn=_door_key,
entities=(
BinarySensorDesc(key='door_open', field='openState',
BinarySensorDesc(key='open', field='openState',
name=None, device_class='door',
value_fn=lambda v: v == 'Open'),
),
-1
View File
@@ -15,7 +15,6 @@ class Capability:
rt_filter: Optional[str] = None # bind only if rt_filter in rep.get('rt', ())
href_prefix: Optional[str] = None # pattern caps only: bind only if href starts with this
match_fn: Optional[Callable[[dict, dict], bool]] = None # match_fn(rep, resources) -> bool
key_fn: Optional[Callable[[str], str]] = None # href -> entity key (pattern caps)
# Rare optional hooks — only operational-state-style resources use these.
active_when: Optional[Callable[[dict], bool]] = None
on_observation: Optional[Callable[[dict, dict], None]] = None
+4 -2
View File
@@ -68,10 +68,12 @@ def discover(
if cap.match_fn is not None and not cap.match_fn(rep, resources):
continue
inst = instance_suffix(href)
key = cap.key_fn(href) if cap.key_fn else None
# Auto-derive key prefix from href: strip digits, join non-empty segs with '_'
segs = [s for s in href.strip('/').split('/') if s and not s.isdigit()]
for desc in cap.entities:
key_override = '_'.join(segs) + '_' + desc.key
out.append(BoundEntity(href=href, capability=cap, desc=desc,
instance=inst, key_override=key))
instance=inst, key_override=key_override))
matched = True
break