diff --git a/src/hyper-light-card.ts b/src/hyper-light-card.ts index cbc315f..7e8d3b2 100644 --- a/src/hyper-light-card.ts +++ b/src/hyper-light-card.ts @@ -8,6 +8,7 @@ import { formatAttributeValue, } from './utils'; import styles from './hyper-light-card-styles.css'; +import { resolve } from 'path'; interface Hass { states: Record; @@ -90,11 +91,6 @@ class HyperLightCard extends LitElement { console.debug('HyperLightCard: firstUpdated called'); this._setupMutationObserver(); this._debouncedExtractColors(); - - // Scroll to the current effect if the dropdown is already open - if (this._isDropdownOpen) { - this._scrollToCurrentEffect(); - } } private _extractColors() { @@ -199,8 +195,16 @@ class HyperLightCard extends LitElement { } updated(changedProperties: Map) { - console.debug('HyperLightCard: updated called', changedProperties); super.updated(changedProperties); + + console.debug('HyperLightCard: updated called', changedProperties); + console.debug('HyperLightCard: current state:', { + isOn: this._isOn, + currentEffect: this._currentEffect, + brightness: this._brightness, + isDropdownOpen: this._isDropdownOpen, + }); + if (changedProperties.has('hass') || changedProperties.has('config')) { this._debouncedUpdate(); } @@ -227,7 +231,12 @@ class HyperLightCard extends LitElement { } render() { - console.debug('HyperLightCard: render called'); + console.debug('HyperLightCard: render called with state:', { + isOn: this._isOn, + currentEffect: this._currentEffect, + brightness: this._brightness, + isDropdownOpen: this._isDropdownOpen, + }); if (!this.hass || !this.config) { console.debug('HyperLightCard: hass or config not available'); return html``; @@ -253,6 +262,14 @@ class HyperLightCard extends LitElement { '--slider-color': this._accentColor, }; + // Scroll and highlight + requestAnimationFrame(() => { + if (this._isDropdownOpen) { + this._scrollToCurrentEffect(); + this._highlightCurrentEffect(); + } + }); + return html`
{ + item.classList.remove('selected'); + if (item.textContent?.trim() === this._currentEffect) { + item.classList.add('selected'); + } + }); + + console.debug('HyperLightCard: Highlighted current effect'); + } + private _toggleDropdown(e: Event) { console.debug('HyperLightCard: _toggleDropdown called'); e.stopPropagation(); @@ -575,14 +606,14 @@ class HyperLightCard extends LitElement { this.requestUpdate(); } - private _selectEffect(effect: string) { + private async _selectEffect(effect: string) { console.debug('HyperLightCard: _selectEffect called', effect); this._currentEffect = effect; this._isDropdownOpen = false; this.requestUpdate(); if (this._isOn) { - this.hass!.callService('light', 'turn_on', { + await this.hass!.callService('light', 'turn_on', { entity_id: this.config!.entity, effect: effect, });