const LUMA_ACTION_VERSION = '0.1.0'; class LumaActionCard 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: 'toggle' }, hold_action: config.hold_action || { action: 'more-info' }, confirmation: config.confirmation || false, ...config }; this._render(); } getCardSize() { return 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]; } _handleClick() { if (!this._hass || !this._config) return; const entity = this._config.entity; if (entity.startsWith('scene.')) { this._hass.callService('scene', 'turn_on', { entity_id: entity }); } else if (entity.startsWith('script.')) { this._hass.callService('script', 'turn_on', { entity_id: entity }); } else { this._hass.callService('homeassistant', 'toggle', { entity_id: entity }); } } _render() { if (!this.shadowRoot || !this._config) return; const accent = this._config.accent_color || '#c9a0dc'; const name = this._config.name || this._getState()?.attributes?.friendly_name || ''; const icon = this._config.icon || 'mdi:play-circle'; const typeLabel = this._config.entity.startsWith('script.') ? 'Script' : 'Scene'; this.shadowRoot.innerHTML = `
${typeLabel}
${name}
Tap to activate
`; this.shadowRoot.querySelector('.card').addEventListener('click', () => this._handleClick()); } } customElements.define('luma-action-card', LumaActionCard); window.customCards = window.customCards || []; window.customCards.push({ type: 'luma-action-card', name: 'Luma Action', description: 'Luma-style scene/script activation card.', preview: true }); console.info(`%c LUMA-ACTION-CARD %c v${LUMA_ACTION_VERSION} `, 'background:#c9a0dc;color:#111;font-weight:bold', 'background:#161a22;color:#c9a0dc');