const LUMA_CLIMATE_VERSION = '0.1.0'; class LumaClimateCard extends HTMLElement { set hass(hass) { this._hass = hass; this._render(); } setConfig(config) { if (!config.entity) throw new Error('Entity is required'); this._config = { entity: config.entity, name: config.name || '', size: config.size || '1x1', accent_color: config.accent_color || '', icon: config.icon || '', tap_action: config.tap_action || { action: 'more-info' }, hold_action: config.hold_action || { action: 'more-info' }, ...config }; this._render(); } getCardSize() { return (this._config?.size === '1x2' || this._config?.size === '2x2') ? 4 : 2; } static getStubConfig() { return { entity: '', name: '', size: '1x1' }; } connectedCallback() { if (!this.shadowRoot) this.attachShadow({ mode: 'open' }); this._render(); } _getState() { return this._hass?.states?.[this._config?.entity]; } _getAccent() { if (this._config?.accent_color) return this._config.accent_color; const s = this._getState(); if (!s) return '#bbbbbb'; switch (s.state) { case 'heat': case 'heat_cool': case 'auto': return '#f0a060'; case 'cool': return '#60b0f0'; default: return '#bbbbbb'; } } _getFillColor() { const s = this._getState(); if (!s) return 'transparent'; switch (s.state) { case 'heat': case 'heat_cool': case 'auto': return 'rgba(240,96,64,0.28)'; case 'cool': return 'rgba(64,144,240,0.28)'; default: return 'rgba(240,160,96,0.15)'; } } _isActive() { const s = this._getState(); return s && s.state !== 'off' && s.state !== 'unavailable'; } _handleClick() { if (!this._hass || !this._config) return; const ev = new Event('hass-more-info', { composed: true }); ev.detail = { entityId: this._config.entity }; this.dispatchEvent(ev); } _render() { if (!this.shadowRoot || !this._config) return; const s = this._getState(); const isActive = this._isActive(); const accent = this._getAccent(); const fill = this._getFillColor(); const name = this._config.name || s?.attributes?.friendly_name || ''; const icon = this._config.icon || 'mdi:thermometer'; const currentTemp = s?.attributes?.current_temperature ?? '--'; const targetTemp = s?.attributes?.temperature ?? '--'; const hvac = s?.state || 'off'; const modeLabel = { heat: 'Heat', cool: 'Cool', heat_cool: 'Auto', auto: 'Auto', off: 'Off' }[hvac] || hvac; this.shadowRoot.innerHTML = `