diff --git a/custom_components/smart_climate/smart-climate-card-clean.js b/custom_components/smart_climate/smart-climate-card-clean.js deleted file mode 100644 index e69de29..0000000 diff --git a/custom_components/smart_climate/smart-climate-card.js b/custom_components/smart_climate/smart-climate-card.js index e9e1906..fb4a84b 100644 --- a/custom_components/smart_climate/smart-climate-card.js +++ b/custom_components/smart_climate/smart-climate-card.js @@ -16,6 +16,8 @@ class SmartClimateCard extends LitElement { return { entity: "" }; } + // ── Component lifecycle / state ───────────────────────────────────────── + setConfig(config) { if (!config.entity) { throw new Error("Entity required"); @@ -79,16 +81,16 @@ class SmartClimateCard extends LitElement {
Temperatuur instellen
- + ${this._overrideTemp}° - +
${isLeaving ? html`
🚶 - ${this.formatSeconds(awayDelayRemaining)} + ${this._formatSeconds(awayDelayRemaining)} tot afwezig
` : ""} @@ -96,9 +98,9 @@ class SmartClimateCard extends LitElement { ${isTimer ? html`
⏱ - ${this.formatTime(remaining)} + ${this._formatTime(remaining)} resterend - +
` : ""} @@ -106,16 +108,16 @@ class SmartClimateCard extends LitElement {
♾ Infinity actief - +
` : ""} ${isNextNode ? html`
📅 - ${this.formatTime(remaining)} + ${this._formatTime(remaining)} tot volgend node - +
` : ""} @@ -136,17 +138,17 @@ class SmartClimateCard extends LitElement { max="480" step="15" .value=${sliderValue} - @input=${this.onSliderInput} - @change=${this.onSliderChange} + @input=${this._onSliderInput} + @change=${this._onSliderChange} /> ${nextNodeDotPct != null ? html`
this.onNextNodeDotClick()} + @click=${() => this._onNextNodeDotClick()} title="Override till next node (${nextNodeMinutes}m)">◆
` : ""}
this.onInfinityDotClick()} + @click=${() => this._onInfinityDotClick()} title="Override infinity">∞
@@ -164,7 +166,9 @@ class SmartClimateCard extends LitElement { `; } - onSliderChange(e) { + // ── Event handlers / service calls ────────────────────────────────────── + + _onSliderChange(e) { const value = Number(e.target.value); const entityId = this.config.entity; @@ -186,33 +190,33 @@ class SmartClimateCard extends LitElement { } } - onSliderInput(e) { + _onSliderInput(e) { const value = Number(e.target.value); const slider = e.target; slider.style.setProperty("--slider-value", `${(value / 480) * 100}%`); } - onNextNodeDotClick() { + _onNextNodeDotClick() { this.hass.callService("smart_climate", "set_override_next_node", { entity_id: this.config.entity, temperature: this._overrideTemp, }); } - onInfinityDotClick() { + _onInfinityDotClick() { this.hass.callService("smart_climate", "set_override_infinity", { entity_id: this.config.entity, temperature: this._overrideTemp, }); } - clearOverride() { + _clearOverride() { this.hass.callService("smart_climate", "clear_override", { entity_id: this.config.entity, }); } - adjustTemp(delta) { + _adjustTemp(delta) { const newTemp = Math.min(25, Math.max(5, this._overrideTemp + delta)); this._overrideTemp = newTemp; const entityId = this.config.entity; @@ -244,14 +248,26 @@ class SmartClimateCard extends LitElement { } } - formatSeconds(seconds) { + // ── Formatters ────────────────────────────────────────────────────────── + + /** + * Format a duration in seconds to a human-readable string (e.g. "2m 30s"). + * @param {number} seconds + * @returns {string} + */ + _formatSeconds(seconds) { const total = Math.max(0, seconds); const m = Math.floor(total / 60); const rem = Math.ceil(total % 60); return m ? `${m}m ${rem}s` : `${rem}s`; } - formatTime(minutes) { + /** + * Format a duration in minutes to a human-readable string (e.g. "1h 30m"). + * @param {number} minutes + * @returns {string} + */ + _formatTime(minutes) { if (minutes < 60) return `${minutes}m`; const h = Math.floor(minutes / 60); const m = minutes % 60; diff --git a/custom_components/smart_climate/smart-climate-config-card.js b/custom_components/smart_climate/smart-climate-config-card.js index 3711c74..7ed5393 100644 --- a/custom_components/smart_climate/smart-climate-config-card.js +++ b/custom_components/smart_climate/smart-climate-config-card.js @@ -22,6 +22,8 @@ class SmartClimateConfigCard extends LitElement { return { entity: "" }; } + // ── Component lifecycle / state ───────────────────────────────────────── + setConfig(config) { if (!config.entity) { throw new Error("Entity required"); @@ -175,12 +177,26 @@ class SmartClimateConfigCard extends LitElement { `; } + // ── Config helpers / service calls ────────────────────────────────────── + + /** + * Adjust a numeric config property by *delta*, clamped to [min, max]. + * @param {string} prop Name of the reactive property to update. + * @param {number} delta Amount to add (may be negative). + * @param {number} min Minimum allowed value. + * @param {number} max Maximum allowed value. + */ _adjust(prop, delta, min, max) { const current = this[prop] ?? 0; this[prop] = Math.min(max, Math.max(min, Math.round((current + delta) * 10) / 10)); this._dirty = true; } + /** + * Format a duration in minutes to a human-readable string (e.g. "1h 30m"). + * @param {number} minutes + * @returns {string} + */ _formatDuration(minutes) { if (minutes < 60) return `${minutes}m`; const h = Math.floor(minutes / 60);