const LUMA_WEATHER_VERSION = '0.1.0'; class LumaWeatherCard 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 || '2x2', icon: config.icon || '', tap_action: config.tap_action || { action: 'more-info' }, hold_action: config.hold_action || { action: 'more-info' }, ...config }; this._render(); } getCardSize() { return 4; } static getStubConfig() { return { entity: '', name: '', size: '2x2' }; } connectedCallback() { if (!this.shadowRoot) this.attachShadow({ mode: 'open' }); this._render(); } _getState() { return this._hass?.states?.[this._config?.entity]; } _getWeatherIcon(condition) { const map = { 'sunny': 'mdi:weather-sunny', 'clear-night': 'mdi:weather-night', 'cloudy': 'mdi:weather-cloudy', 'fog': 'mdi:weather-fog', 'partlycloudy': 'mdi:weather-partly-cloudy', 'rainy': 'mdi:weather-rainy', 'pouring': 'mdi:weather-pouring', 'snowy': 'mdi:weather-snowy', 'lightning': 'mdi:weather-lightning', 'lightning-rainy': 'mdi:weather-lightning-rainy', 'hail': 'mdi:weather-hail', 'windy': 'mdi:weather-windy', 'windy-variant': 'mdi:weather-windy-variant', 'exceptional': 'mdi:alert-circle', }; return map[condition] || 'mdi:weather-sunny'; } _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 condition = s?.state || 'sunny'; const temp = s?.attributes?.temperature ?? '--'; const humidity = s?.attributes?.humidity ?? '--'; const wind = s?.attributes?.wind_speed ?? '--'; const icon = this._config.icon || this._getWeatherIcon(condition); const conditionLabel = condition.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()); this.shadowRoot.innerHTML = `
${temp}°
${conditionLabel}
Humidity
${humidity}%
Wind
${wind} km/h
`; this.shadowRoot.querySelector('.card').addEventListener('click', () => this._handleClick()); } } customElements.define('luma-weather-card', LumaWeatherCard); window.customCards = window.customCards || []; window.customCards.push({ type: 'luma-weather-card', name: 'Luma Weather', description: 'Luma-style weather hero card with temperature and conditions.', preview: true }); console.info(`%c LUMA-WEATHER-CARD %c v${LUMA_WEATHER_VERSION} `, 'background:#f0d080;color:#111;font-weight:bold', 'background:#161a22;color:#f0d080');