adaptive-lighting/.github/update-strings.py
Bas Nijholt c4b8e28ea8
fix: restore hassfest and Home Assistant CI
## Summary
- fix hassfest validation by replacing raw options-description URLs with Home Assistant translation placeholders
- extend the pytest CI matrix to cover the latest patch release for each Home Assistant month, plus dev
- align CI/dev container Python versions and tests with newer Home Assistant behavior

## Validation
- GitHub Actions pytest matrix passed for 2024.12.5 through 2026.4.3 plus dev
- Docker passed for linux/amd64 and linux/arm64
- hassfest, HACS validation, pre-commit, pre-commit.ci, markdown-code-runner, docs build, and Release Drafter passed
2026-04-24 11:31:53 -07:00

70 lines
2.1 KiB
Python

"""Update strings.json and en.json from const.py."""
import json
import sys
from pathlib import Path
import homeassistant.helpers.config_validation as cv
import yaml
sys.path.append(str(Path(__file__).parent.parent))
from custom_components.adaptive_lighting import const
folder = Path("custom_components") / "adaptive_lighting"
strings_fname = folder / "strings.json"
en_fname = folder / "translations" / "en.json"
with strings_fname.open() as f:
strings = json.load(f)
# Set "options"
data = {}
data_description = {}
for k, _, typ in const.VALIDATION_TUPLES:
desc = const.DOCS[k]
if len(desc) > 40 and typ not in (bool, cv.entity_ids):
data[k] = k
data_description[k] = desc
else:
data[k] = f"{k}: {desc}"
strings["options"]["step"]["init"]["data"] = data
strings["options"]["step"]["init"]["data_description"] = data_description
# Set "services"
services_filename = Path("custom_components") / "adaptive_lighting" / "services.yaml"
with open(services_filename) as f: # noqa: PTH123
services = yaml.safe_load(f)
services_json = {}
for service_name, dct in services.items():
services_json[service_name] = {
"name": service_name,
"description": dct["description"],
"fields": {},
}
for field_name, field in dct["fields"].items():
services_json[service_name]["fields"][field_name] = {
"description": field["description"],
"name": field_name,
}
strings["services"] = services_json
# Write changes to strings.json
with strings_fname.open("w") as f:
json.dump(strings, f, indent=2, ensure_ascii=False)
f.write("\n")
# Sync changes from strings.json to en.json
with en_fname.open() as f:
en = json.load(f)
en["config"]["step"]["user"] = strings["config"]["step"]["user"]
en["options"]["step"]["init"]["data"] = data
en["options"]["step"]["init"]["data_description"] = data_description
en["options"]["step"]["init"]["description"] = strings["options"]["step"]["init"][
"description"
]
en["services"] = services_json
with en_fname.open("w") as f:
json.dump(en, f, indent=2, ensure_ascii=False)
f.write("\n")