Skip to content

Commit 3838c8f

Browse files
author
root
committed
ci: verify generated en.json is current and every entity has a name
Adds a 'Generated Files Check' workflow (push to main + PRs): 1. Regenerates the English translations via merge_topics.py and fails if the committed en.json differs - merge_topics otherwise only runs in the version-bump workflow, so a manual catalog/translation edit could drift. 2. Fails if any generated entity entry has a null/empty name, i.e. an entity that would render as the device name only. Both pass on current main (en.json regenerates with no diff, 0 nameless entities). Pairs with the library-side check in tomer-w/victron_mqtt.
1 parent f86b400 commit 3838c8f

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Generated Files Check
2+
3+
# Verifies that the generated English translations are in sync with the
4+
# vendored victron_mqtt.json and that every entity actually has a display
5+
# name. merge_topics.py currently only runs in the version-bump workflow,
6+
# so a manual catalog/translation edit could otherwise drift unnoticed.
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
pull_request:
13+
types: [opened, reopened, synchronize]
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
translations:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v7
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v6
28+
with:
29+
python-version: '3.14'
30+
31+
- name: Regenerate en.json from victron_mqtt.json
32+
run: python3 .github/scripts/merge_topics.py
33+
34+
- name: Fail if en.json is out of date
35+
run: |
36+
en="custom_components/victron_mqtt/translations/en.json"
37+
if ! git diff --quiet "$en"; then
38+
echo "::error file=$en::en.json is out of date. Run 'python3 .github/scripts/merge_topics.py' and commit the result (it regenerates entity names from victron_mqtt.json)."
39+
git --no-pager diff "$en"
40+
exit 1
41+
fi
42+
echo "en.json is up to date."
43+
44+
- name: Every entity has a display name
45+
run: |
46+
python - <<'PY'
47+
import json, sys
48+
49+
en_path = "custom_components/victron_mqtt/translations/en.json"
50+
with open(en_path, encoding="utf-8") as f:
51+
en = json.load(f)
52+
53+
# An entry with a "name" key that is null/empty renders as the device
54+
# name only. Entries without a "name" key at all (main-device topics)
55+
# use the device name on purpose and are fine.
56+
missing = []
57+
for entity_type, entries in en.get("entity", {}).items():
58+
for key, entry in entries.items():
59+
if "name" in entry and entry["name"] in (None, ""):
60+
missing.append(f"{entity_type}.{key}")
61+
62+
if missing:
63+
print("::error::These entities have no display name in en.json, so HA "
64+
"shows only the device name. The name comes from the topic's "
65+
"generic_name in the victron_mqtt library - set it there and "
66+
"re-run merge_topics.py:")
67+
for item in missing:
68+
print(f" - {item}")
69+
sys.exit(1)
70+
print("OK - every generated entity translation has a non-empty name.")
71+
PY

0 commit comments

Comments
 (0)