const LUMA_RANGE_VERSION = '0.1.0'; class LumaRangeCard 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 || '', glow_color: config.glow_color || '', icon: config.icon || '', tap_action: config.tap_action || { action: 'more-info' }, hold_action: config.hold_action || { action: 'more-info' }, confirmation: config.confirmation || false, ...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]; } _isOn() { const s = this._getState(); return s && s.state === 'on'; } _getBrightness() { const s = this._getState(); if (!s || s.state !== 'on') return 0; const b = parseFloat(s.attributes?.brightness); return isNaN(b) ? 0 : Math.round(b / 255 * 100); } _getAccent() { if (this._config?.accent_color) return this._config.accent_color; const s = this._getState(); if (s?.attributes?.rgb_color) { const [r, g, b] = s.attributes.rgb_color; return `rgb(${r},${g},${b})`; } return this._isOn() ? '#fab95c' : '#bbbbbb'; } _getGlow() { if (this._config?.glow_color) return this._config.glow_color; const s = this._getState(); if (s?.attributes?.rgb_color) { const [r, g, b] = s.attributes.rgb_color; return `rgb(${r},${g},${b})`; } return '#fab95c'; } _handleClick() { if (!this._hass || !this._config) return; const action = this._config.tap_action?.action || 'more-info'; if (action === 'toggle') { this._hass.callService('homeassistant', 'toggle', { entity_id: this._config.entity }); } else { 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 isOn = this._isOn(); const pct = this._getBrightness(); const accent = this._getAccent(); const glow = this._getGlow(); const name = this._config.name || this._getState()?.attributes?.friendly_name || ''; const icon = this._config.icon || 'mdi:lightbulb'; const label = isOn ? `${pct}%` : 'Off'; const glowAlpha = isOn ? (pct / 100 * 0.35).toFixed(2) : '0'; this.shadowRoot.innerHTML = `