Update cookcli-card.js
This commit is contained in:
parent
c603a0d4ec
commit
e3935f5822
101
dist/cookcli-card.js
vendored
101
dist/cookcli-card.js
vendored
|
|
@ -183,79 +183,54 @@ class CookCliCard extends HTMLElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CookCliCardEditor extends HTMLElement {
|
class CookCliCardEditor extends LitElement {
|
||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
this._config = config || {};
|
this._config = config || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
set hass(hass) {
|
static getConfigForm() {
|
||||||
this._hass = hass;
|
return {
|
||||||
}
|
schema: [
|
||||||
|
{
|
||||||
// Définit le schéma du formulaire (une entrée par champ configurable)
|
name: "title",
|
||||||
get _schema() {
|
selector: { text: {} },
|
||||||
return [
|
},
|
||||||
{
|
{
|
||||||
name: "title",
|
name: "dashboard_path",
|
||||||
selector: { text: {} },
|
selector: { text: {} },
|
||||||
|
helper: "Laisser vide pour naviguer dans le dashboard courant",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "entry_id",
|
||||||
|
selector: { text: {} },
|
||||||
|
helper: "Optionnel — ID d'entrée si plusieurs serveurs CookCLI",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
computeLabel: (schema) => {
|
||||||
|
const labels = {
|
||||||
|
title: "Titre",
|
||||||
|
dashboard_path: "Chemin du dashboard",
|
||||||
|
entry_id: "Entry ID",
|
||||||
|
};
|
||||||
|
return labels[schema.name] || schema.name;
|
||||||
},
|
},
|
||||||
{
|
computeHelper: (schema) => {
|
||||||
name: "dashboard_path",
|
switch (schema.name) {
|
||||||
selector: { text: {} },
|
case "entity":
|
||||||
helper: "Laisser vide pour naviguer dans le dashboard courant",
|
return "This text describes the function of the entity selector";
|
||||||
|
case "unit":
|
||||||
|
return "The unit of measurement for this card";
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
},
|
},
|
||||||
{
|
assertConfig: (config) => {
|
||||||
name: "entry_id",
|
if (config.other_option) {
|
||||||
selector: { text: {} },
|
throw new Error("'other_option' is unexpected.");
|
||||||
helper: "Optionnel — ID d'entrée si plusieurs serveurs CookCLI",
|
}
|
||||||
},
|
},
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fournit les libellés des champs
|
|
||||||
_computeLabel(schema) {
|
|
||||||
const labels = {
|
|
||||||
title: "Titre",
|
|
||||||
dashboard_path: "Chemin du dashboard",
|
|
||||||
entry_id: "Entry ID",
|
|
||||||
};
|
};
|
||||||
return labels[schema.name] || schema.name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gère les changements dans le formulaire
|
|
||||||
_valueChanged(ev) {
|
|
||||||
if (!this._config || !this._hass) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newConfig = { ...this._config, ...ev.detail.value };
|
|
||||||
|
|
||||||
this._config = newConfig;
|
|
||||||
|
|
||||||
const event = new CustomEvent("config-changed", {
|
|
||||||
detail: { config: newConfig },
|
|
||||||
bubbles: true,
|
|
||||||
composed: true,
|
|
||||||
});
|
|
||||||
this.dispatchEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
if (!this._hass) return;
|
|
||||||
|
|
||||||
this.innerHTML = `
|
|
||||||
<ha-form
|
|
||||||
.hass=${this._hass}
|
|
||||||
.data=${this._config}
|
|
||||||
.schema=${this._schema}
|
|
||||||
.computeLabel=${this._computeLabel.bind(this)}
|
|
||||||
@value-changed=${this._valueChanged.bind(this)}
|
|
||||||
></ha-form>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
connectedCallback() {
|
|
||||||
this.render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("cookcli-card", CookCliCard);
|
customElements.define("cookcli-card", CookCliCard);
|
||||||
|
|
|
||||||
Reference in a new issue