Course selection is now a writable select entity sourced from each
device's own x.com.samsung.da.editCourseList (via a new options-as-callable
form on SelectDesc, reading the coordinator's full resource snapshot
instead of just the entity's own href), rather than a hardcoded course
table baked into Python. A MostUsed_ field on the same resource was
considered as a fallback but rejected after byte-level analysis showed it
doesn't reliably encode a course list. When a device never populates
editCourseList, the selector isn't created at all (exists_fn now takes
(rep, resources) to check a sibling href, matching the existing
match_fn(rep, resources) pattern).
Display names moved out of Python into strings.json/translations under
entity.select.{washer,dishwasher}_cycle.state.*, matching this
integration's existing translation_key convention (fridge.py's ice_type,
flex_zone_mode, etc.) instead of hardcoding English names in code.
25 lines
784 B
Python
25 lines
784 B
Python
"""Adapter: BoundEntity list → flat state dict and command dispatch."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from .discovery import BoundEntity
|
|
|
|
|
|
def _key(b: BoundEntity) -> str:
|
|
return f"{b.key_override or b.desc.key}{b.instance}"
|
|
|
|
|
|
def flatten(bound: list[BoundEntity], resources: dict) -> dict[str, Any]:
|
|
"""Map bound entities to their current scalar values."""
|
|
out: dict[str, Any] = {}
|
|
for b in bound:
|
|
rep = resources.get(b.href) or {}
|
|
if b.desc.exists_fn is not None and not b.desc.exists_fn(rep, resources):
|
|
continue
|
|
if b.desc.rep_fn is not None:
|
|
out[_key(b)] = b.desc.rep_fn(rep)
|
|
elif b.desc.field:
|
|
out[_key(b)] = b.desc.value_fn(rep.get(b.desc.field))
|
|
return out
|