From 22bee99cff272660e604be5a836942276ce16c7f Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Wed, 16 Sep 2026 16:35:06 +0200 Subject: [PATCH] Update cookcli-recipe-strategy.js --- dist/cookcli-recipe-strategy.js | 99 +++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/dist/cookcli-recipe-strategy.js b/dist/cookcli-recipe-strategy.js index d58cd8c..1bbd92f 100644 --- a/dist/cookcli-recipe-strategy.js +++ b/dist/cookcli-recipe-strategy.js @@ -55,30 +55,8 @@ class CookCliDashboardStrategy extends HTMLElement { return { title: "Recettes", icon: "mdi:chef-hat" }; } - static getConfigForm() { - return { - schema: [ - { name: "title", selector: { text: {} }, label: "Titre" }, - { - name: "timer_entity", - selector: { entity: { domain: "timer" } }, - label: "Entité minuteur", - helper: "Ex: timer.recette_en_cours", - }, - { - name: "step_entity", - selector: { entity: { domain: "input_number" } }, - label: "Entité étape", - helper: "Ex: input_number.recette_etape", - }, - { - name: "entry_id", - selector: { text: {} }, - label: "Entry ID", - helper: "Optionnel — si plusieurs serveurs CookCLI", - }, - ], - }; + static getConfigElement() { + return document.createElement("cookcli-strategy-editor"); } static configRequired = true; @@ -405,8 +383,81 @@ class CookCliRecipeViewStrategy extends HTMLElement { } } +class CookcliStrategyEditor extends HTMLElement { + setConfig(config) { + this._config = config; + } + + set hass(hass) { + this._hass = hass; + } + + // Méthode appelée quand l'utilisateur modifie un champ + _valueChanged(ev) { + if (!this._config || !this._hass) { + return; + } + const target = ev.target; + const newConfig = { ...this._config }; + + // Mettre à jour la clé correspondant au nom du champ + newConfig[target.configValue] = target.value; + + // Informer Home Assistant du changement + this.dispatchEvent( + new CustomEvent("config-changed", { + bubbles: true, + composed: true, + detail: { config: newConfig }, + }) + ); + } + + // Méthode de rendu (obligatoire pour afficher le formulaire) + connectedCallback() { + this.innerHTML = ` +
+ + + +
+ `; + } + + configChanged(newConfig) { + this.dispatchEvent( + new CustomEvent("config-changed", { + bubbles: true, + composed: true, + detail: { config: newConfig }, + }) + ); + } +} + customElements.define("ll-strategy-dashboard-cookcli", CookCliDashboardStrategy); customElements.define("ll-strategy-view-cookcli-recipe", CookCliRecipeViewStrategy); +customElements.define("cookcli-strategy-editor", CookcliStrategyEditor); window.customStrategies = window.customStrategies || []; window.customStrategies.push({