UX-01: translate the add-on config, and order it by task
checks / unit (pull_request) Successful in 5m1s

The add-on had NO translations/ directory, so Home Assistant fell back to
rendering the raw option KEYS. An operator opening Configuration read
`unit_sign_disagree_w`, `saturation_cycles`, `integrator_max_w` - seventy of
them, in file order, with no description and no way to tell a constant derived
from 1890 closed-loop test runs from their own inverter's rating.

⚠️ PRESENTATION ONLY. Not one default, not one schema range and not one line of
behaviour moved. The 175 non-comment lines of config.yaml are byte-identical to
release/1.0's, reordered; the only comment lines that changed are the group
banners and five sentences whose "above"/"below" the reorder made false.

* translations/en.yaml and translations/nl.yaml: a name and a description for
  all 70 options and all 7 per-entry keys of the `inverters:` repeatable
  section. The Dutch is written for a Flemish homeowner - afname/injectie,
  kwartierpiek, capaciteitstarief - not transliterated from the English.
* ⭐ Every derived constant says WHERE IT CAME FROM and whether to touch it.
  `unit_sign_disagree_s` cites its 1890 closed-loop runs (SAFETY-30);
  `circulation_w` its 924 runs and the measured 400 W knee (SAFETY-31);
  `meter_freeze_s` its 2399 s capture (SAFETY-18); `bms_soc_floor` register
  0x0560. The two numbers that are the operator's - max_w and peak_cap_w - say
  "THIS IS YOUR NUMBER". `cycle_cost_threshold_eur`, which is neither, says it
  is an open product question (OPT-08).
* config.yaml reordered into task order in BOTH halves, comments carried with
  their keys: hardware -> meter -> ratings and limits -> tariff -> maintenance
  -> safety -> advanced.
  ⚠️ test_inverter.py:1788's trap is PRESERVED: the nested per-entry `max_w:`
  still precedes the flat one under `schema:`, and `inverters: []` still ships
  in the `options:` half. Moving the nested block below the flat one is a 1-byte
  edit; it was run and goes red in test_inverter.py and test_translations.py.
* tools/supervisor_shape_probe.py section F MEASURES the result against
  ghcr.io/home-assistant/amd64-hassio-supervisor:2026.08.0 - Supervisor's own
  _read_app_translations(), its own UiOptions, and the frontend's label
  resolution transcribed from the shipped bundle - and prints every rendered row
  in both languages. `all cases passed`, exit 0.
* ⚠️ ONE MEASURED NEGATIVE RESULT, NOT GLOSSED: the per-entry keys inside the
  `inverters:` section still render RAW on frontend 20250925.1, because a
  list-of-objects goes to ha-selector-object and the converter sets no `label`
  and no `translation_key`. The `fields:` translations are shipped and validated
  - that is Supervisor's own shape for this - but this card does not claim they
  reach the screen. The `inverters` label and description do.
* test_translations.py: a translation naming a non-existent option, or an option
  with no translation, fails CI - both directions, both languages, top level and
  per entry. Mutation-tested BOTH WAYS: eleven in-process mutations each
  required to NAME the key they broke, plus a negative control; six more run on
  disk through the purge-and-re-read protocol. Two of the eleven are the ones
  that cost the WHOLE FILE rather than one label - an unrecognised top-level
  block, and a `network:` value that is not a string. Supervisor drops a file
  that fails SCHEMA_APP_TRANSLATIONS with only a log warning, so those silently
  return the entire tab to raw keys; neither is reachable through the
  `configuration:` coverage, which is why they were hunted for and closed.
* tools/translations_lint.py is the hand parser CI needs (no PyYAML in the
  add-on image) and the probe grades it, key by key and string by string,
  against Supervisor's own loader. It is strict and RAISES rather than skipping;
  nine malformed shapes prove it.

Full 20-file suite green (19 existing + test_translations.py).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwRLw7eKYj2byVdwB6kbjU
This commit is contained in:
Claude Opus 5
2026-09-05 12:02:56 +02:00
parent 3993f9f32b
commit fef6ef20a4
8 changed files with 1772 additions and 315 deletions
@@ -272,6 +272,180 @@ except Exception as e: # noqa: BLE001
show("Supervisor's UI renderer survives the shape", False, f"{type(e).__name__}: {e}")
print("\n== F. UX-01: the TRANSLATED Configuration tab, rendered ==")
# ⚠️ WHAT THIS SECTION MEASURES, AND WHY IT IS NOT AN ASSERTION ABOUT A FILE.
# UX-01 adds translations/en.yaml and translations/nl.yaml. Whether they reach
# an operator depends on two pieces of somebody else's software, not on us:
#
# 1. SUPERVISOR decides whether a file is loaded at all.
# `supervisor/store/data.py:_read_app_translations()` globs this directory,
# keys each file by its STEM, and runs it through `SCHEMA_APP_TRANSLATIONS`.
# ⚠️ A FILE THAT FAILS THAT SCHEMA IS DROPPED WITH A LOG WARNING AND
# NOTHING ELSE: `except (ConfigurationFileError, vol.Invalid): _LOGGER.
# warning(...); continue`. The add-on then renders raw keys and the only
# trace is one line in the Supervisor log. So the loader is RUN here, out
# of the release image, rather than the schema being re-implemented.
# 2. THE FRONTEND decides what it does with what Supervisor loaded. The
# resolution below is not invented: it is transcribed from the shipped
# bundle in THIS image, `api/panel/frontend_latest/5680.*.js`
# (frontend 20250925.1), which reads
#
# _getTranslationEntry(lang,s,o){let e=this.addon.translations[lang]?.
# configuration; if(e){if(o?.path)for(const t of o.path)
# if(e=e[t]?.fields,!e)return; return e[s.name]}}
# computeLabel =(s,_,o)=>this._getTranslationEntry(this.hass.language,s,o)?.name
# ||this._getTranslationEntry("en",s,o)?.name||s.name
# computeHelper=(s,o) =>this._getTranslationEntry(this.hass.language,s,o)?.description
# ||this._getTranslationEntry("en",s,o)?.description||""
# _filteredSchema=(opts,schema)=>schema.filter(e=>e.name in opts||e.required)
#
# i.e. the fallback is PER KEY, en is the second chance, and the raw key
# name is the third.
from supervisor.apps.validate import SCHEMA_APP_TRANSLATIONS # noqa: E402
from supervisor.store.data import _read_app_translations # noqa: E402
TRANSLATIONS = _read_app_translations(Path("/w"))
show("Supervisor's OWN translation loader accepts both files - a file that "
"fails SCHEMA_APP_TRANSLATIONS is DROPPED with a log warning and the tab "
"silently goes back to raw keys, so 'it is on disk' is not the question",
set(TRANSLATIONS) == {"en", "nl"}, sorted(TRANSLATIONS))
ui = UiOptions(None)(schema)
print(f" the Configuration tab renders {len(ui)} fields, in `schema:` order "
"(App.schema_ui is UiOptions(...)(data['schema']), so the ORDER IS THE "
"SCHEMA BLOCK'S and not the options block's)")
def _entry(lang, name, path=()):
node = TRANSLATIONS.get(lang, {}).get("configuration")
if not node:
return None
for step in path:
node = (node.get(step) or {}).get("fields")
if not node:
return None
return node.get(name)
def _label(lang, name, path=()):
for lg in (lang, "en"):
e = _entry(lg, name, path)
if e and e.get("name"):
return e["name"], lg
return name, "RAW KEY"
def _helper(lang, name, path=()):
for lg in (lang, "en"):
e = _entry(lg, name, path)
if e and e.get("description"):
return e["description"], lg
return "", "NONE"
# ⚠️ EVERY FIELD, PRINTED. This is the transcript the card asks for: what the
# owner's Supervisor puts on the screen, not a claim that it would look nice.
for lang in ("en", "nl"):
print(f"\n --- as rendered at hass.language == {lang!r} "
f"(the owner's HA runs Europe/Brussels) ---")
for node in ui:
lbl, src = _label(lang, node["name"])
hlp, hsrc = _helper(lang, node["name"])
flag = "" if src == lang else f" [name from {src}]"
print(f" {node['name']:28s} -> {lbl}{flag}")
print(f" {'':28s} {hlp[:150]}{'...' if len(hlp) > 150 else ''}")
for sub in node.get("schema", ()):
slbl, ssrc = _label(lang, sub["name"], (node["name"],))
print(f" · {sub['name']:24s} -> {slbl}"
+ ("" if ssrc == lang else f" [{ssrc}]"))
_raw = [n["name"] for n in ui if _label("en", n["name"])[1] == "RAW KEY"]
show("NOT ONE top-level field falls through to its raw key name in `en` - "
f"which is what the tab rendered for all {len(ui)} of them before this "
f"card, because there was no translations/ directory at all. Raw: {_raw}",
not _raw)
_nohelp = [n["name"] for n in ui if not _helper("en", n["name"])[0]]
show("...and not one is left without a description, which is the half that "
f"says WHETHER TO TOUCH IT. Missing: {_nohelp}", not _nohelp)
_nl_missing = [n["name"] for n in ui if _label("nl", n["name"])[1] != "nl"]
show("...and every one of them is translated in `nl` too, so nothing on the "
f"owner's own screen falls back to English. Falling back: {_nl_missing}",
not _nl_missing)
# ⚠️ THE HONEST HALF, AND IT IS A NEGATIVE RESULT. `inverters` is a
# list-of-objects, so UiOptions gives it type "schema" WITH multiple: True, and
# `_convertSchemaElement` sends exactly that case to a SELECTOR rather than to a
# nested ha-form:
#
# if("schema"===t.type&&!t.multiple) return {...type:"expandable"...} <- not us
# if("schema"===t.type){const o={};for(const a of t.schema)
# o[a.name]={required:a.required,selector:...}; return {object:{multiple:t.multiple,fields:o}}}
#
# and ha-selector-object labels those fields with
#
# computeLabel=e=>{const t=this.selector.object?.translation_key;
# if(this.localizeValue&&t){...}
# return this.selector.object?.fields?.[e.name]?.label||e.name}
#
# `_convertSchemaElementToSelector` sets neither `label` nor `translation_key`,
# so ON THIS FRONTEND the per-entry keys inside the repeatable section render as
# `setpoint_entity`, `max_w`, `bms_soc_floor` - RAW - however well they are
# translated here. The `fields:` block is still shipped and still validated,
# because it is the shape Supervisor's own schema defines for exactly this and
# it is what a frontend that wires `label` through would consume; but this card
# must not claim it reaches the operator today, and the count below is asserted
# so that the day it changes, this transcript says so.
_multi = [n for n in ui if n.get("multiple") and n.get("type") == "schema"]
show("`inverters` is rendered as a REPEATABLE SECTION (type schema, multiple), "
"which is CFG-04's measurement re-confirmed",
[n["name"] for n in _multi] == ["inverters"], json.dumps(_multi)[:200])
show("⚠️ MEASURED AND NEGATIVE: this frontend gives that section's per-entry "
"keys to ha-selector-object, which labels them `fields[name].label || "
"name` - and the converter sets no `label` and no `translation_key`. So "
"the per-entry translations below are SHIPPED AND VALIDATED but do NOT "
"reach the screen on 20250925.1. The top-level `inverters` label and "
"description DO.",
bool(_multi) and all("label" not in s and "translation_key" not in s
for n in _multi for s in n.get("schema", ())),
"per-entry keys as rendered today: "
+ ", ".join(s["name"] for n in _multi for s in n.get("schema", ())))
# ⚠️ AND THE HAND PARSER CI USES IS GRADED AGAINST THIS LOADER, KEY BY KEY.
# test_translations.py runs in the add-on's CI image, which has no PyYAML, so it
# parses these files with tools/translations_lint.py. A hand parser that
# disagrees with the real loader is a check whose data cannot reach the failure
# it names, so the two are compared here - where both are available - rather
# than assumed to agree.
sys.path.insert(0, "/probe")
import translations_lint as _tl # noqa: E402
_mismatch = []
for lang in ("en", "nl"):
hand = _tl.parse_translation_file(f"/w/translations/{lang}.yaml")
real = {"configuration": TRANSLATIONS[lang].get("configuration", {})}
# SCHEMA_APP_TRANSLATIONS fills `description: None` for an absent one; the
# hand parser simply has no key. Normalise that ONE difference and nothing
# else, so a real disagreement cannot hide behind the normalisation.
def _norm(d):
return {k: {kk: vv for kk, vv in v.items() if vv is not None
and kk != "fields"}
| ({"fields": _norm(v["fields"])} if v.get("fields") else {})
for k, v in d.items()}
if _norm(hand.get("configuration", {})) != _norm(real["configuration"]):
a, b = _norm(hand.get("configuration", {})), _norm(real["configuration"])
_mismatch += [f"{lang}:{k}" for k in sorted(set(a) | set(b))
if a.get(k) != b.get(k)]
show("the hand parser CI uses (tools/translations_lint.py) returns EXACTLY "
"what Supervisor's own loader returns, for both files, key by key and "
f"string by string. Disagreements: {_mismatch}", not _mismatch)
_cfg_text = Path("/w/config.yaml").read_text(encoding="utf-8")
_probs = []
for lang in ("en", "nl"):
_probs += _tl.audit(
_cfg_text,
{"configuration": TRANSLATIONS[lang].get("configuration", {})}, lang)
show(f"...and the coverage audit is clean against the real loader's view too. "
f"Problems: {_probs}", not _probs)
# ⚠️ THE EXIT CODE IS PART OF THE INSTRUMENT. Without it the probe prints FAIL
# and still succeeds, and a transcript is only evidence if a wrong answer is
# distinguishable from a right one by something other than reading it.