Skip to content

Commit 7483cbc

Browse files
authored
Add files via upload
1 parent 0e4d108 commit 7483cbc

File tree

1 file changed

+36
-232
lines changed

1 file changed

+36
-232
lines changed

dist/fast-search-card.js

Lines changed: 36 additions & 232 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,32 +2814,6 @@ class FastSearchCard extends HTMLElement {
28142814
background: rgba(255,255,255,0.05);
28152815
border-radius: 12px;
28162816
}
2817-
2818-
.timer-actions {
2819-
display: flex;
2820-
gap: 8px;
2821-
align-items: center;
2822-
}
2823-
2824-
.timer-edit,
2825-
.timer-delete {
2826-
width: 32px;
2827-
height: 32px;
2828-
background: rgba(255,255,255,0.1);
2829-
border: none;
2830-
border-radius: 50%;
2831-
cursor: pointer;
2832-
display: flex;
2833-
align-items: center;
2834-
justify-content: center;
2835-
transition: all 0.2s ease;
2836-
flex-shrink: 0;
2837-
}
2838-
2839-
.timer-edit:hover {
2840-
background: rgba(0, 122, 255, 0.2);
2841-
transform: scale(1.1);
2842-
}
28432817

28442818
.quick-timer-title {
28452819
font-size: 14px;
@@ -9049,21 +9023,11 @@ class FastSearchCard extends HTMLElement {
90499023
return;
90509024
}
90519025

9026+
console.log(`🎯 Erstelle Timer: ${action} in ${totalMinutes} Minuten`);
9027+
90529028
try {
9053-
// NEU: Prüfen ob Edit-Modus
9054-
if (this.editingTimer) {
9055-
console.log(`🔧 Timer bearbeiten: ${this.editingTimer.id} - ${totalMinutes} Minuten`);
9056-
9057-
// Timer bearbeiten (Sie müssen diese Funktion implementieren)
9058-
await this.updateTimerTime(this.editingTimer.id, totalMinutes);
9059-
9060-
// Edit-Modus zurücksetzen
9061-
this.editingTimer = null;
9062-
} else {
9063-
// Normal: Neuen Timer erstellen
9064-
console.log(`🎯 Erstelle Timer: ${action} in ${totalMinutes} Minuten`);
9065-
await this.createActionTimer(item, action, totalMinutes);
9066-
}
9029+
// Verwende deine bestehende Timer-Erstellung
9030+
await this.createActionTimer(item, action, totalMinutes);
90679031

90689032
// Schließe den Picker
90699033
const parentContainer = this.shadowRoot.querySelector('.minimal-time-picker').closest('.shortcuts-tab-content');
@@ -9075,80 +9039,10 @@ class FastSearchCard extends HTMLElement {
90759039
}, 500);
90769040

90779041
} catch (error) {
9078-
console.error('❌ Fehler beim Timer:', error);
9042+
console.error('❌ Fehler beim Erstellen des Timers:', error);
90799043
}
90809044
}
90819045

9082-
// KORRIGIERT: Timer by ID laden
9083-
async getTimerById(timerId) {
9084-
try {
9085-
// Verwende die Timer aus der bereits geladenen Liste
9086-
if (this.lastLoadedTimers) {
9087-
const timer = this.lastLoadedTimers.find(t => t.schedule_id === timerId);
9088-
if (timer) {
9089-
console.log('✅ Timer aus Cache gefunden:', timer);
9090-
return timer;
9091-
}
9092-
}
9093-
9094-
// Fallback: Nochmal alle Timer laden
9095-
const allSchedules = await this._hass.callWS({
9096-
type: 'scheduler'
9097-
});
9098-
9099-
return allSchedules.find(s => s.schedule_id === timerId);
9100-
9101-
} catch (error) {
9102-
console.error('Fehler beim Laden des Timers:', error);
9103-
9104-
// Minimal-Timer-Objekt für Edit-Zwecke
9105-
return {
9106-
schedule_id: timerId,
9107-
action: 'turn_off', // Default-Aktion
9108-
name: 'Timer'
9109-
};
9110-
}
9111-
}
9112-
9113-
// FALLBACK: Timer aus der aktuellen Anzeige holen
9114-
getCurrentTimerFromList(timerId) {
9115-
// Vereinfachter Ansatz: Nimm die ursprüngliche Aktion vom Button
9116-
if (this.lastLoadedTimers) {
9117-
return this.lastLoadedTimers.find(t => t.schedule_id === timerId);
9118-
}
9119-
9120-
// Minimal-Timer-Objekt für Edit-Zwecke
9121-
return {
9122-
schedule_id: timerId,
9123-
action: 'turn_off', // Default-Aktion
9124-
name: 'Timer'
9125-
};
9126-
}
9127-
9128-
// KORRIGIERT: Timer-Zeit aktualisieren
9129-
async updateTimerTime(timerId, newTotalMinutes) {
9130-
try {
9131-
console.log(`🔧 Timer bearbeiten: ${timerId} -> ${newTotalMinutes} min`);
9132-
9133-
const currentTimer = this.lastLoadedTimers?.find(t => t.schedule_id === timerId);
9134-
const future = new Date(Date.now() + newTotalMinutes * 60 * 1000);
9135-
9136-
await this._hass.callService('scheduler', 'edit', {
9137-
entity_id: timerId, // Direkt die Timer-ID ohne Prefix
9138-
timeslots: [{
9139-
start: future.toTimeString().slice(0, 5),
9140-
actions: currentTimer.timeslots[0].actions
9141-
}]
9142-
});
9143-
9144-
console.log(`✅ Timer ${timerId} bearbeitet`);
9145-
9146-
} catch (error) {
9147-
console.error('❌ Edit fehlgeschlagen:', error);
9148-
throw error;
9149-
}
9150-
}
9151-
91529046
closeMinimalTimePicker(parentContainer) {
91539047
const timePickerContainer = parentContainer.querySelector('.minimal-time-picker');
91549048
if (timePickerContainer) {
@@ -9582,36 +9476,35 @@ class FastSearchCard extends HTMLElement {
95829476
console.error('❌ Timer Fehler:', error);
95839477
// TODO: Error Toast (später)
95849478
}
9585-
9586-
9587-
9479+
95889480
async loadActiveTimers(entityId) {
9589-
console.log('🔍 DEBUG: loadActiveTimers aufgerufen für:', entityId);
9590-
95919481
const container = this.shadowRoot.getElementById(`active-timers-${entityId}`);
95929482
if (!container) return;
95939483

95949484
container.innerHTML = '<div class="loading-timers">Lade Timer...</div>';
95959485

95969486
try {
9487+
// KORRIGIERT: Verwende die richtige API
95979488
const allSchedules = await this._hass.callWS({
9598-
type: 'scheduler'
9489+
type: 'scheduler' // ← Das war der Fehler!
95999490
});
96009491

96019492
console.log('📋 Alle Scheduler Items (korrekte API):', allSchedules);
96029493

9603-
// WICHTIG: Filter für diese Entity UND nur echte Timer (dieser Code fehlte!)
9494+
// Filter für diese Entity UND nur echte Timer (keine Wochentage)
96049495
const entityTimers = allSchedules.filter(schedule => {
96059496
// Prüfe ob diese Entity in den timeslots/actions vorkommt
96069497
const belongsToEntity = schedule.timeslots && schedule.timeslots.some(slot =>
96079498
slot.actions && slot.actions.some(action => action.entity_id === entityId)
96089499
);
9500+
96099501
// Timer = einmalige Ausführung (erkennt man am Namen oder fehlendem repeat_type)
96109502
const isTimer = !schedule.weekdays ||
96119503
schedule.weekdays.length === 0 ||
96129504
(schedule.name && schedule.name.includes('min)')) || // Timer haben oft "(30min)" im Namen
96139505
schedule.repeat_type === 'once' ||
96149506
!schedule.repeat_type;
9507+
96159508
// DEBUG: Zeige alle relevanten Schedules
96169509
if (belongsToEntity) {
96179510
console.log(`🔍 TIMER DEBUG - Schedule: ${schedule.name}, weekdays: ${JSON.stringify(schedule.weekdays)}, isTimer: ${isTimer}`);
@@ -9622,21 +9515,7 @@ class FastSearchCard extends HTMLElement {
96229515

96239516
console.log(`🎯 Timer für ${entityId}:`, entityTimers);
96249517

9625-
this.lastLoadedTimers = entityTimers;
9626-
9627-
console.log('🔍 DEBUG: Rufe renderActiveTimers auf...');
9628-
console.log('🔍 DEBUG: this.renderActiveTimers existiert?', typeof this.renderActiveTimers);
9629-
9630-
// Prüfen ob die Funktion existiert
9631-
if (typeof this.renderActiveTimers === 'function') {
9632-
this.renderActiveTimers(entityTimers, entityId);
9633-
} else {
9634-
console.error('❌ renderActiveTimers Funktion existiert nicht!');
9635-
// Fallback - direkt HTML setzen
9636-
container.innerHTML = entityTimers.length > 0
9637-
? `<div class="no-timers">${entityTimers.length} Timer gefunden</div>`
9638-
: '<div class="no-timers">Keine aktiven Timer</div>';
9639-
}
9518+
this.renderActiveTimers(entityTimers, entityId);
96409519

96419520
} catch (error) {
96429521
console.error('❌ Fehler beim Laden der Timer:', error);
@@ -9649,7 +9528,6 @@ class FastSearchCard extends HTMLElement {
96499528

96509529

96519530

9652-
96539531
renderActiveTimers(timers, entityId) {
96549532
const container = this.shadowRoot.getElementById(`active-timers-${entityId}`);
96559533
if (!container) return;
@@ -9680,24 +9558,18 @@ class FastSearchCard extends HTMLElement {
96809558
<span class="timer-time">${timeUntil}</span>
96819559
</div>
96829560
</div>
9683-
<div class="timer-actions">
9684-
<button class="timer-edit" data-timer-id="${timer.schedule_id}" title="Timer bearbeiten">
9685-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
9686-
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
9687-
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
9688-
</svg>
9689-
</button>
9690-
<button class="timer-delete" data-timer-id="${timer.schedule_id}" title="Timer löschen">
9691-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
9692-
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
9693-
<path d="M4 7l16 0" />
9694-
<path d="M10 11l0 6" />
9695-
<path d="M14 11l0 6" />
9696-
<path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" />
9697-
<path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" />
9698-
</svg>
9699-
</button>
9700-
</div>
9561+
9562+
<button class="timer-delete" data-timer-id="${timer.schedule_id}" title="Timer löschen">
9563+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
9564+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
9565+
<path d="M4 7l16 0" />
9566+
<path d="M10 11l0 6" />
9567+
<path d="M14 11l0 6" />
9568+
<path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" />
9569+
<path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" />
9570+
</svg>
9571+
</button>
9572+
97019573
</div>
97029574
`;
97039575
}).join('');
@@ -9707,84 +9579,15 @@ class FastSearchCard extends HTMLElement {
97079579
<div class="active-timers-list">${timerHTML}</div>
97089580
`;
97099581

9710-
// Event Listeners für Edit Buttons (bereits vorhanden)
9711-
container.querySelectorAll('.timer-edit').forEach(btn => {
9712-
btn.addEventListener('click', () => {
9713-
const timerId = btn.dataset.timerId;
9714-
this.editTimer(timerId, entityId);
9715-
});
9716-
});
9717-
9718-
// ✅ NEU: Event Listeners für Delete Buttons hinzufügen
9582+
// Event Listeners für Delete Buttons
97199583
container.querySelectorAll('.timer-delete').forEach(btn => {
97209584
btn.addEventListener('click', () => {
97219585
const timerId = btn.dataset.timerId;
9722-
// Optional: Bestätigungsdialog
9723-
if (confirm('Timer wirklich löschen?')) {
9724-
this.deleteTimer(timerId, entityId);
9725-
}
9586+
this.deleteTimer(timerId, entityId);
97269587
});
97279588
});
97289589
}
97299590

9730-
async editTimer(timerId, entityId) {
9731-
console.log(`🔧 Timer bearbeiten: ${timerId}`);
9732-
9733-
try {
9734-
const timer = await this.getTimerById(timerId);
9735-
if (!timer) {
9736-
console.error('Timer nicht gefunden');
9737-
return;
9738-
}
9739-
9740-
// Debug: Schauen welche Container verfügbar sind
9741-
console.log('🔍 DEBUG: Suche Container für entityId:', entityId);
9742-
9743-
// Verschiedene Container-Selektoren probieren
9744-
let parentContainer = this.shadowRoot.querySelector(`#timer-section-${entityId}`);
9745-
9746-
if (!parentContainer) {
9747-
console.log('🔍 timer-section nicht gefunden, probiere shortcuts-tab-content...');
9748-
parentContainer = this.shadowRoot.querySelector('.shortcuts-tab-content.active');
9749-
}
9750-
9751-
if (!parentContainer) {
9752-
console.log('🔍 shortcuts-tab-content nicht gefunden, probiere timer-control...');
9753-
parentContainer = this.shadowRoot.querySelector(`#timer-control-${entityId}`);
9754-
}
9755-
9756-
if (!parentContainer) {
9757-
console.log('🔍 Alle verfügbaren Container:');
9758-
const allContainers = this.shadowRoot.querySelectorAll('[id*="timer"]');
9759-
allContainers.forEach(c => console.log('- Container:', c.id, c));
9760-
9761-
console.error('❌ Kein geeigneter Container gefunden!');
9762-
return;
9763-
}
9764-
9765-
console.log('✅ Container gefunden:', parentContainer);
9766-
9767-
// Edit-Modus setzen
9768-
this.editingTimer = {
9769-
id: timerId,
9770-
action: timer.action || 'turn_off',
9771-
entityId: entityId
9772-
};
9773-
9774-
// Item-Objekt für Time Picker
9775-
const itemObj = {
9776-
id: entityId,
9777-
name: 'Timer Edit'
9778-
};
9779-
9780-
// Time Picker anzeigen
9781-
this.showMinimalTimePicker(itemObj, timer.action || 'turn_off', parentContainer, false);
9782-
9783-
} catch (error) {
9784-
console.error('❌ Fehler beim Bearbeiten:', error);
9785-
}
9786-
}
9787-
97889591
getNextExecution(timer) {
97899592
// Zuerst prüfen ob next_execution Attribut vorhanden ist
97909593
if (timer.next_execution) {
@@ -9838,22 +9641,23 @@ class FastSearchCard extends HTMLElement {
98389641
}
98399642
return '⚙️ Aktion';
98409643
}
9841-
9644+
98429645
async deleteTimer(timerId, entityId) {
98439646
try {
9844-
console.log(`🗑️ Timer löschen: ${timerId}`);
9845-
9846-
await this._hass.callService('scheduler', 'remove', {
9847-
entity_id: timerId // Direkt die Timer-ID ohne Prefix
9647+
// KORRIGIERT: Verwende callApi statt callService
9648+
await this._hass.callApi('POST', 'scheduler/remove', {
9649+
schedule_id: timerId
98489650
});
98499651

9850-
console.log(`✅ Timer ${timerId} gelöscht`);
9851-
setTimeout(() => this.loadActiveTimers(entityId), 500);
9652+
console.log(`🗑️ Timer ${timerId} gelöscht`);
9653+
9654+
// Timer Liste neu laden
9655+
this.loadActiveTimers(entityId);
98529656

98539657
} catch (error) {
9854-
console.error('❌ Löschen fehlgeschlagen:', error);
9658+
console.error('❌ Fehler beim Löschen:', error);
98559659
}
9856-
}
9660+
}
98579661

98589662
async loadAndDisplayHistory(item, period) {
98599663
const timelineContainer = this.shadowRoot.getElementById(`history-timeline-${item.id}`);

0 commit comments

Comments
 (0)