class SpaceWeatherCard extends HTMLElement { constructor() { super(); this.attachShadow({mode: 'open'}); } setConfig(config) { this._config = config; } set hass(hass) { this._hass = hass; this.render(); } render() { if (!this.shadowRoot) return; this.shadowRoot.innerHTML = ` Space Weather Conditions R${this._getStateValue('sensor.space_weather_scale_r')} S${this._getStateValue('sensor.space_weather_scale_s')} G${this._getStateValue('sensor.space_weather_scale_g')} `; this._attachClickListeners(); } _getStateValue(entityId) { const state = this._hass.states[entityId]; return state ? state.state : ''; } _getStateAttribute(entityId, attribute) { const state = this._hass.states[entityId]; return state ? state.attributes[attribute] || '' : ''; } _getNumericState(entityId) { const stateValue = this._getStateValue(entityId); return stateValue.substring(1); } _attachClickListeners() { const scaleItems = this.shadowRoot.querySelectorAll('.scale-item'); scaleItems.forEach(item => { item.addEventListener('click', () => { const entityId = item.dataset.entityId; this._handleClick(entityId); }); }); } _handleClick(entityId) { const event = new Event('hass-more-info', {composed: true}); event.detail = {entityId}; this.dispatchEvent(event); } getCardSize() { return 3; } } customElements.define('space-weather-current', SpaceWeatherCard);