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.
22 lines
998 B
Python
22 lines
998 B
Python
"""A Capability binds one OCF resource href to the entities it produces."""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Callable, Optional
|
|
|
|
from .entities import SamsungEntityDescription
|
|
|
|
|
|
@dataclass(frozen=True, kw_only=True)
|
|
class Capability:
|
|
href: Optional[str] = None
|
|
entities: tuple[SamsungEntityDescription, ...] = ()
|
|
poll_tier: str = 'warm' # 'hot' | 'warm' | 'cold'
|
|
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
|
|
# 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
|
|
project: Optional[Callable[[dict, dict], dict]] = None
|