Skip to content

Commit 9a31ead

Browse files
authored
Update fast-search-card.js
1 parent 7a656eb commit 9a31ead

File tree

1 file changed

+64
-29
lines changed

1 file changed

+64
-29
lines changed

dist/fast-search-card.js

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10742,63 +10742,98 @@ class FastSearchCard extends HTMLElement {
1074210742
container.innerHTML = '<div class="loading-schedules">Lade Zeitpläne...</div>';
1074310743

1074410744
try {
10745-
// DEBUG: Alle Schedule-Entitäten anzeigen
1074610745
const allEntities = this._hass.states;
1074710746
const allSchedules = Object.keys(allEntities)
1074810747
.filter(key => key.startsWith('switch.schedule_'))
1074910748
.map(key => allEntities[key]);
1075010749

10751-
console.log('🔍 DEBUG: Alle Schedule-Entitäten:', allSchedules);
10752-
console.log('🔍 DEBUG: Suche nach entityId:', entityId);
10750+
console.log('🔍 DEBUG: Alle Schedule-Entitäten:', allSchedules.length);
1075310751

10754-
// DEBUG: Erste Schedule-Entität genauer anschauen
10755-
if (allSchedules.length > 0) {
10756-
console.log('🔍 DEBUG: Erste Schedule Attributes:', allSchedules[0].attributes);
10757-
console.log('🔍 DEBUG: Erste Schedule Timeslots:', allSchedules[0].attributes.timeslots);
10758-
console.log('🔍 DEBUG: Erste Schedule Actions in Timeslot:',
10759-
allSchedules[0].attributes.timeslots?.[0]?.actions);
10760-
}
10761-
10762-
// DEBUG: Einfache Anzeige ALLER Schedules (erstmal ohne Filter)
10763-
if (allSchedules.length === 0) {
10764-
container.innerHTML = '<div class="no-schedules">❌ Keine Zeitpläne im System gefunden</div>';
10752+
// KORRIGIERTES FILTERING: entities statt actions in timeslots
10753+
const scheduleEntities = allSchedules.filter(schedule => {
10754+
const entities = schedule.attributes.entities || [];
10755+
const hasMatch = entities.includes(entityId);
10756+
console.log(`🔍 Schedule ${schedule.entity_id}: entities=${JSON.stringify(entities)}, hasMatch=${hasMatch}`);
10757+
return hasMatch;
10758+
});
10759+
10760+
console.log(`📋 Gefundene Zeitpläne für ${entityId}:`, scheduleEntities.length);
10761+
10762+
if (scheduleEntities.length === 0) {
10763+
container.innerHTML = '<div class="no-schedules">Keine aktiven Zeitpläne</div>';
1076510764
return;
1076610765
}
1076710766

10768-
// DEBUG: Zeige alle Schedules mit Details
10769-
const debugHTML = allSchedules.map((schedule, index) => {
10767+
// KORRIGIERTE ANZEIGE mit neuer Datenstruktur
10768+
const schedulesHTML = scheduleEntities.map(schedule => {
10769+
const isEnabled = schedule.state === 'on';
10770+
const nextTrigger = schedule.attributes.next_trigger;
10771+
const weekdays = schedule.attributes.weekdays || [];
1077010772
const timeslots = schedule.attributes.timeslots || [];
10773+
const entities = schedule.attributes.entities || [];
10774+
const actions = schedule.attributes.actions || [];
10775+
const scheduleName = schedule.attributes.friendly_name || schedule.entity_id;
10776+
10777+
// Erste Timeslot für Anzeige - Zeit extrahieren aus "HH:MM:SS - HH:MM:SS"
1077110778
const firstTimeslot = timeslots[0];
10772-
const actions = firstTimeslot?.actions || [];
10779+
let timeString = 'Unbekannt';
10780+
if (firstTimeslot && typeof firstTimeslot === 'string') {
10781+
const timeMatch = firstTimeslot.match(/^(\d{2}:\d{2})/);
10782+
timeString = timeMatch ? timeMatch[1] : firstTimeslot;
10783+
}
10784+
10785+
// Action für diese Entity finden
10786+
const entityIndex = entities.indexOf(entityId);
10787+
const actionForEntity = entityIndex >= 0 ? actions[entityIndex] : 'Unbekannt';
1077310788

1077410789
return `
10775-
<div class="schedule-item" style="border: 2px solid #007AFF; margin: 10px 0; padding: 10px;">
10790+
<div class="schedule-item ${isEnabled ? 'enabled' : 'disabled'}" data-entity-id="${schedule.entity_id}">
1077610791
<div class="schedule-info">
10777-
<div><strong>Schedule ${index + 1}:</strong> ${schedule.attributes.friendly_name || schedule.entity_id}</div>
10778-
<div><strong>State:</strong> ${schedule.state}</div>
10779-
<div><strong>Weekdays:</strong> ${JSON.stringify(schedule.attributes.weekdays)}</div>
10780-
<div><strong>Time:</strong> ${firstTimeslot?.start || 'Unbekannt'}</div>
10781-
<div><strong>Actions:</strong> ${JSON.stringify(actions)}</div>
10782-
<div><strong>Target Entity:</strong> ${actions.map(a => a.entity_id).join(', ')}</div>
10783-
<div><strong>Matches ${entityId}?</strong> ${actions.some(a => a.entity_id === entityId) ? '✅ JA' : '❌ NEIN'}</div>
10792+
<div class="schedule-main">
10793+
<span class="schedule-name">${actionForEntity} um ${timeString}</span>
10794+
</div>
10795+
<div class="schedule-details">
10796+
<span class="schedule-days">${this.formatWeekdays(weekdays)}</span>
10797+
${nextTrigger ? `<span class="schedule-next">Nächste: ${this.formatNextTrigger(nextTrigger)}</span>` : ''}
10798+
</div>
10799+
</div>
10800+
<div class="schedule-controls">
10801+
<button class="schedule-toggle-btn" data-action="toggle" title="${isEnabled ? 'Deaktivieren' : 'Aktivieren'}">
10802+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
10803+
${isEnabled ?
10804+
'<path d="M6 18L18 6M6 6l12 12"/>' :
10805+
'<polyline points="20,6 9,17 4,12"/>'
10806+
}
10807+
</svg>
10808+
</button>
10809+
<button class="schedule-delete-btn" data-action="delete" title="Löschen">
10810+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
10811+
<polyline points="3,6 5,6 21,6"/>
10812+
<path d="m19,6v14a2,2 0 0,1-2,2H7a2,2 0 0,1-2-2V6m3,0V4a2,2 0 0,1,2-2h4a2,2 0 0,1,2,2v2"/>
10813+
<line x1="10" y1="11" x2="10" y2="17"/>
10814+
<line x1="14" y1="11" x2="14" y2="17"/>
10815+
</svg>
10816+
</button>
1078410817
</div>
1078510818
</div>
1078610819
`;
1078710820
}).join('');
1078810821

1078910822
container.innerHTML = `
1079010823
<div class="schedules-header">
10791-
<h4>🔍 DEBUG: Alle Zeitpläne (${allSchedules.length})</h4>
10792-
<p style="font-size: 12px; color: #666;">Suche nach: ${entityId}</p>
10824+
<h4>Aktive Zeitpläne (${scheduleEntities.length})</h4>
1079310825
</div>
1079410826
<div class="schedules-list">
10795-
${debugHTML}
10827+
${schedulesHTML}
1079610828
</div>
1079710829
`;
1079810830

10831+
// Event Listeners für Schedule Controls
10832+
this.setupScheduleControlEvents(container, entityId);
10833+
1079910834
} catch (error) {
1080010835
console.error('❌ Fehler beim Laden der Zeitpläne:', error);
10801-
container.innerHTML = `<div class="schedules-error">Fehler: ${error.message}</div>`;
10836+
container.innerHTML = '<div class="schedules-error">Fehler beim Laden der Zeitpläne</div>';
1080210837
}
1080310838
}
1080410839

0 commit comments

Comments
 (0)