diff --git a/dist/cookcli-card.js b/dist/cookcli-card.js index 937049c..98b8885 100644 --- a/dist/cookcli-card.js +++ b/dist/cookcli-card.js @@ -50,8 +50,18 @@ class CookCliCard extends HTMLElement { this._render(); } - static getConfigElement() { - return document.createElement("cookcli-card-editor"); + /** + * É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" }, + ], + }; } set hass(hass) { @@ -185,75 +195,6 @@ 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",