diff --git a/cards/luma-action-card.js b/cards/luma-action-card.js new file mode 100644 index 0000000..497b7f4 --- /dev/null +++ b/cards/luma-action-card.js @@ -0,0 +1,81 @@ +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 = ` + +
Connect your TV to Home Assistant
+ +