feat: enhance color handling in templates and dashboard with hex support

This commit is contained in:
2026-05-10 12:55:39 +02:00
parent 8f8c3655db
commit 565c4078bb
5 changed files with 39 additions and 8 deletions
+12 -1
View File
@@ -49,6 +49,11 @@ def _normalize_templates(raw: dict) -> dict[str, dict]:
color = incoming.get("color")
if isinstance(color, int):
out[key]["color"] = color
elif isinstance(color, str):
try:
out[key]["color"] = parse_color(color)
except ValueError:
pass
image_url = incoming.get("image_url")
if isinstance(image_url, str) and image_url.strip():
@@ -74,10 +79,16 @@ def load_templates(path: str | Path) -> dict[str, dict]:
def save_templates(path: str | Path, templates: dict) -> None:
p = Path(path)
normalized = _normalize_templates(templates)
serialized = deepcopy(normalized)
for tpl in serialized.values():
color = tpl.get("color")
if isinstance(color, int):
tpl["color"] = f"#{color:06X}"
p.parent.mkdir(parents=True, exist_ok=True)
tmp = p.with_suffix(p.suffix + ".tmp")
tmp.write_text(json.dumps(normalized, indent=2,
tmp.write_text(json.dumps(serialized, indent=2,
sort_keys=True) + "\n", encoding="utf-8")
tmp.replace(p)