From afeaea709ff365d1fe9cf7ce7538462bdf0388f3 Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Wed, 16 Sep 2026 16:23:41 +0200 Subject: [PATCH] Update cookcli-card.js --- dist/cookcli-card.js | 83 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/dist/cookcli-card.js b/dist/cookcli-card.js index 98b8885..937049c 100644 --- a/dist/cookcli-card.js +++ b/dist/cookcli-card.js @@ -50,18 +50,8 @@ class CookCliCard extends HTMLElement { this._render(); } - /** - * Éditeur de configuration automatique intégré à Home Assistant. - * HA utilise ce schéma pour générer le formulaire visuel. - */ - static getConfigForm() { - return { - schema: [ - { name: "title", selector: { text: {} }, label: "Titre" }, - { name: "dashboard_path", selector: { text: {} }, label: "Chemin du dashboard", helper: "Laisser vide pour le dashboard courant" }, - { name: "entry_id", selector: { text: {} }, label: "Entry ID", helper: "Optionnel — si plusieurs serveurs CookCLI" }, - ], - }; + static getConfigElement() { + return document.createElement("cookcli-card-editor"); } set hass(hass) { @@ -195,6 +185,75 @@ class CookCliCard extends HTMLElement { customElements.define("cookcli-card", CookCliCard); +class CookCliCardEditor extends HTMLElement { + setConfig(config) { + this._config = config || {}; + } + + set hass(hass) { + this._hass = hass; + if (!this._dashboards) { + this._loadDashboards(); + } + } + + async _loadDashboards() { + try { + const result = await this._hass.callWS({ type: "lovelace/dashboards/list" }); + // Filtrer pour ne garder que les dashboards avec un url_path + this._dashboards = result.filter((d) => d.url_path); + this._render(); + } catch (e) { + console.error("Erreur dashboards/list", e); + this._dashboards = []; + this._render(); + } + } + + _render() { + if (!this._dashboards) { + this.innerHTML = `
Chargement…
`; + return; + } + + const options = this._dashboards + .map((d) => { + const path = `/${d.url_path}`; + const selected = this._config.dashboard_path === d.url_path ? "selected" : ""; + return ``; + }) + .join(""); + + this.innerHTML = ` +
+ + + + ${options} + +
+ `; + + this.querySelector("ha-select")?.addEventListener("change", (ev) => { + const newConfig = { ...this._config, dashboard_path: ev.target.value }; + this.dispatchEvent( + new CustomEvent("config-changed", { + bubbles: true, + composed: true, + detail: { config: newConfig }, + }) + ); + }); + } +} + +customElements.define("cookcli-card-editor", CookCliCardEditor); + window.customCards = window.customCards || []; window.customCards.push({ type: "cookcli-card",