@@ -7869,10 +7869,69 @@ class FastSearchCard extends HTMLElement {
78697869 e.stopPropagation();
78707870 this.handleBackClick();
78717871 });
7872+
7873+ // NEU: Heart-Button Event-Listener
7874+ const favoriteButton = this.shadowRoot.querySelector('.favorite-button');
7875+ if (favoriteButton) {
7876+ favoriteButton.addEventListener('click', (e) => {
7877+ e.stopPropagation();
7878+ this.handleFavoriteClick(item);
7879+ });
7880+ }
78727881
78737882 this.setupCustomDetailTabs(item);
78747883 }
78757884
7885+
7886+ async handleFavoriteClick(item) {
7887+ try {
7888+ const favoriteLabel = await this.getFavoriteLabel();
7889+ const isFavorite = await this.isFavorite(item);
7890+
7891+ if (isFavorite) {
7892+ // Favorit entfernen
7893+ await this._hass.callService('label', 'remove', {
7894+ entity_id: item.id,
7895+ label_id: favoriteLabel
7896+ });
7897+ console.log('💔 Removed from favorites:', item.name);
7898+ } else {
7899+ // Als Favorit hinzufügen
7900+ await this._hass.callService('label', 'assign', {
7901+ entity_id: item.id,
7902+ label_id: favoriteLabel
7903+ });
7904+ console.log('💖 Added to favorites:', item.name);
7905+ }
7906+
7907+ // Button-State sofort aktualisieren
7908+ this.updateFavoriteButtonState(item);
7909+
7910+ } catch (error) {
7911+ console.error('❌ Favorite action failed:', error);
7912+ }
7913+ }
7914+
7915+ async isFavorite(item) {
7916+ try {
7917+ const favoriteLabel = await this.getFavoriteLabel();
7918+ const state = this._hass.states[item.id];
7919+ return state?.attributes?.labels?.includes(favoriteLabel) || false;
7920+ } catch (error) {
7921+ console.warn('❌ Could not check favorite status:', error);
7922+ return false;
7923+ }
7924+ }
7925+
7926+ async updateFavoriteButtonState(item) {
7927+ const favoriteButton = this.shadowRoot.querySelector('.favorite-button');
7928+ if (!favoriteButton) return;
7929+
7930+ const isFav = await this.isFavorite(item);
7931+ favoriteButton.classList.toggle('active', isFav);
7932+ }
7933+
7934+
78767935 handleBackClick() {
78777936 this.isDetailView = false;
78787937 const searchPanel = this.shadowRoot.querySelector('.search-panel');
@@ -7917,6 +7976,18 @@ class FastSearchCard extends HTMLElement {
79177976 this.handleBackClick();
79187977 });
79197978
7979+ // Heart-Button Event-Listener
7980+ const favoriteButton = this.shadowRoot.querySelector('.favorite-button');
7981+ if (favoriteButton) {
7982+ favoriteButton.addEventListener('click', (e) => {
7983+ e.stopPropagation();
7984+ this.handleFavoriteClick(item);
7985+ });
7986+
7987+ // NEU: Initial Favorite State setzen
7988+ this.updateFavoriteButtonState(item);
7989+ }
7990+
79207991 this.setupDetailTabs(item);
79217992
79227993 const iconBackground = detailPanel.querySelector('.icon-background');
0 commit comments