@@ -12559,48 +12559,45 @@ class FastSearchCard extends HTMLElement {
1255912559 }
1256012560 }
1256112561
12562- // 🎧 EVENT-BASIERTE TTS-ÜBERWACHUNG (ersetzt Timer-Logik )
12562+ // 🎧 EVENT-BASIERTE TTS-ÜBERWACHUNG (überwacht Media Content )
1256312563 async startTTSMonitoring(entityId) {
1256412564 console.log('🎧 Starting TTS monitoring...');
1256512565
12566+ // 💾 TTS-Start-Zustand speichern
12567+ const initialState = this._hass.states[entityId];
12568+ const ttsContentId = initialState.attributes.media_content_id;
12569+ console.log('🎤 TTS Content ID:', ttsContentId);
12570+
1256612571 let checkCount = 0;
12567- const maxChecks = 60; // Max 60 Sekunden überwachen
12572+ const maxChecks = 60;
1256812573
1256912574 const monitorInterval = setInterval(async () => {
1257012575 checkCount++;
1257112576
12572- // 🚫 Abbruch-Bedingungen
1257312577 if (!this.isTTSActive || checkCount > maxChecks) {
1257412578 console.log('🛑 TTS monitoring stopped (timeout or inactive)');
1257512579 clearInterval(monitorInterval);
1257612580 await this.finalizeTTSProcess(entityId);
1257712581 return;
1257812582 }
1257912583
12580- // 🔍 Player-Status prüfen
1258112584 const currentState = this._hass.states[entityId];
12582- const playerState = currentState?.state ;
12585+ const currentContentId = currentState.attributes.media_content_id ;
1258312586
12584- console.log(`🔍 TTS Monitor check ${checkCount}: Player state = ${playerState }`);
12587+ console.log(`🔍 TTS Monitor check ${checkCount}: Content = ${currentContentId }`);
1258512588
12586- // 🎯 TTS beendet erkennen: Player ist nicht mehr 'playing'
12587- if (playerState !== 'playing' ) {
12588- console.log('🎉 TTS completed! Player no longer playing ');
12589+ // 🎯 TTS beendet: Media Content hat sich geändert oder ist leer
12590+ if (currentContentId !== ttsContentId || !currentContentId ) {
12591+ console.log('🎉 TTS completed! Media content changed ');
1258912592 clearInterval(monitorInterval);
1259012593
12591- // Kurz warten für sauberen Übergang
1259212594 await new Promise(resolve => setTimeout(resolve, 500));
12593-
12594- // Player-Kontext wiederherstellen
1259512595 await this.restorePlayerContext();
12596-
12597- // Button-Status zurücksetzen
1259812596 await this.finalizeTTSProcess(entityId);
1259912597 }
1260012598
12601- }, 1000); // Jede Sekunde prüfen
12599+ }, 1000);
1260212600
12603- // Store interval for potential cleanup
1260412601 this.ttsMonitorInterval = monitorInterval;
1260512602 }
1260612603
0 commit comments