Skip to content

Commit 5bfedc3

Browse files
authored
Update fast-search-card.js
1 parent 7483cbc commit 5bfedc3

File tree

1 file changed

+138
-22
lines changed

1 file changed

+138
-22
lines changed

dist/fast-search-card.js

Lines changed: 138 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,6 +3008,31 @@ class FastSearchCard extends HTMLElement {
30083008
background: rgba(255, 0, 0, 0.2);
30093009
transform: scale(1.1);
30103010
}
3011+
3012+
.timer-controls {
3013+
display: flex;
3014+
align-items: center;
3015+
gap: 8px;
3016+
}
3017+
3018+
.timer-edit {
3019+
width: 32px;
3020+
height: 32px;
3021+
background: rgba(255, 255, 255, 0.1);
3022+
border: none;
3023+
border-radius: 50%;
3024+
cursor: pointer;
3025+
display: flex;
3026+
align-items: center;
3027+
justify-content: center;
3028+
transition: all 0.2s ease;
3029+
color: var(--text-primary);
3030+
}
3031+
3032+
.timer-edit:hover {
3033+
background: rgba(0, 122, 255, 0.2);
3034+
transform: scale(1.1);
3035+
}
30113036

30123037
.no-timers {
30133038
text-align: center;
@@ -8553,14 +8578,29 @@ class FastSearchCard extends HTMLElement {
85538578

85548579

85558580

8556-
showMinimalTimePicker(item, action, container, isScheduleMode = false) {
8557-
console.log(`🎯 Zeige Minimal Time Picker für ${action}, Schedule Mode: ${isScheduleMode}`);
8581+
8582+
showMinimalTimePicker(item, action, container, isScheduleMode = false, existingTimerData = null) {
8583+
8584+
const isEditMode = !!existingTimerData;
8585+
console.log(`🎯 Zeige Minimal Time Picker für ${action}, Schedule Mode: ${isScheduleMode}, Edit Mode: ${isEditMode}`);
85588586

85598587
// State variables
8588+
let initialHours = isScheduleMode ? 18 : 0;
8589+
let initialMinutes = isScheduleMode ? 0 : 30;
8590+
let scheduleId = null;
8591+
8592+
if (isEditMode) {
8593+
const totalMinutes = existingTimerData.duration;
8594+
initialHours = Math.floor(totalMinutes / 60);
8595+
initialMinutes = totalMinutes % 60;
8596+
scheduleId = existingTimerData.schedule_id;
8597+
}
8598+
85608599
this.timePickerState = {
8561-
selectedHours: isScheduleMode ? 18 : 0,
8562-
selectedMinutes: isScheduleMode ? 0 : 30,
8600+
selectedHours: initialHours,
8601+
selectedMinutes: initialMinutes,
85638602
isScheduleMode: isScheduleMode,
8603+
scheduleId: scheduleId,
85648604
hoverHours: false,
85658605
hoverMinutes: false
85668606
};
@@ -9023,12 +9063,18 @@ class FastSearchCard extends HTMLElement {
90239063
return;
90249064
}
90259065

9026-
console.log(`🎯 Erstelle Timer: ${action} in ${totalMinutes} Minuten`);
9066+
// Prüfen ob Edit-Modus oder Create-Modus
9067+
if (this.timePickerState.scheduleId) {
9068+
// EDIT-MODUS
9069+
console.log(`💾 Aktualisiere Timer ${this.timePickerState.scheduleId} auf ${totalMinutes} Minuten.`);
9070+
await this.updateActionTimer(this.timePickerState.scheduleId, item, action, totalMinutes);
9071+
} else {
9072+
// CREATE-MODUS (wie bisher)
9073+
console.log(`🎯 Erstelle Timer: ${action} in ${totalMinutes} Minuten`);
9074+
await this.createActionTimer(item, action, totalMinutes);
9075+
}
90279076

90289077
try {
9029-
// Verwende deine bestehende Timer-Erstellung
9030-
await this.createActionTimer(item, action, totalMinutes);
9031-
90329078
// Schließe den Picker
90339079
const parentContainer = this.shadowRoot.querySelector('.minimal-time-picker').closest('.shortcuts-tab-content');
90349080
this.closeMinimalTimePicker(parentContainer);
@@ -9559,16 +9605,25 @@ class FastSearchCard extends HTMLElement {
95599605
</div>
95609606
</div>
95619607

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>
9608+
<div class="timer-controls">
9609+
<button class="timer-edit" data-timer-id="${timer.schedule_id}" title="Timer bearbeiten">
9610+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
9611+
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
9612+
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
9613+
</svg>
9614+
</button>
9615+
9616+
<button class="timer-delete" data-timer-id="${timer.schedule_id}" title="Timer löschen">
9617+
<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">
9618+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
9619+
<path d="M4 7l16 0" />
9620+
<path d="M10 11l0 6" />
9621+
<path d="M14 11l0 6" />
9622+
<path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" />
9623+
<path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" />
9624+
</svg>
9625+
</button>
9626+
</div>
95729627

95739628
</div>
95749629
`;
@@ -9579,11 +9634,11 @@ class FastSearchCard extends HTMLElement {
95799634
<div class="active-timers-list">${timerHTML}</div>
95809635
`;
95819636

9582-
// Event Listeners für Delete Buttons
9583-
container.querySelectorAll('.timer-delete').forEach(btn => {
9637+
// Event Listeners für Edit Buttons
9638+
container.querySelectorAll('.timer-edit').forEach(btn => {
95849639
btn.addEventListener('click', () => {
95859640
const timerId = btn.dataset.timerId;
9586-
this.deleteTimer(timerId, entityId);
9641+
this.handleEditTimerClick(timerId, entityId);
95879642
});
95889643
});
95899644
}
@@ -13481,7 +13536,68 @@ class FastSearchCard extends HTMLElement {
1348113536
`;
1348213537
}
1348313538

13484-
13539+
13540+
async handleEditTimerClick(scheduleId, entityId) {
13541+
console.log(`✏️ Bearbeitung für Timer ${scheduleId} angefordert.`);
13542+
13543+
try {
13544+
const allSchedules = await this._hass.callWS({ type: 'scheduler' });
13545+
const timerToEdit = allSchedules.find(s => s.schedule_id === scheduleId);
13546+
13547+
if (!timerToEdit) {
13548+
alert("Dieser Timer wurde bereits ausgeführt oder gelöscht und kann nicht bearbeitet werden.");
13549+
this.loadActiveTimers(entityId);
13550+
return;
13551+
}
13552+
13553+
const action = this.getActionNameFromService(timerToEdit.actions[0].service, timerToEdit.actions[0].service_data);
13554+
const nextExecution = new Date(timerToEdit.next_trigger);
13555+
const durationMinutes = Math.round((nextExecution - new Date()) / 60000);
13556+
13557+
const item = this.allItems.find(i => i.id === entityId);
13558+
const container = this.shadowRoot.querySelector(`[data-shortcuts-content="timer"]`);
13559+
13560+
this.showMinimalTimePicker(item, action, container, false, {
13561+
schedule_id: scheduleId,
13562+
duration: durationMinutes > 0 ? durationMinutes : 0,
13563+
action: action
13564+
});
13565+
} catch (error) {
13566+
console.error('❌ Fehler beim Laden der Timer-Daten:', error);
13567+
alert('Fehler beim Laden der Timer-Daten');
13568+
}
13569+
}
13570+
13571+
getActionNameFromService(service, service_data) {
13572+
const serviceAction = service.split('.')[1];
13573+
if (serviceAction === 'turn_on' && service_data && service_data.brightness_pct) {
13574+
return `dim_${service_data.brightness_pct}`;
13575+
}
13576+
return serviceAction;
13577+
}
13578+
13579+
async updateActionTimer(scheduleId, item, action, durationMinutes) {
13580+
console.log(`📡 Aktualisiere Timer ${scheduleId} mit Dauer ${durationMinutes}min.`);
13581+
const future = new Date(Date.now() + durationMinutes * 60 * 1000);
13582+
const timeString = future.toTimeString().slice(0, 5);
13583+
const { service, serviceData } = this.getActionServiceData(item, action);
13584+
13585+
try {
13586+
await this._hass.callService('scheduler', 'edit', {
13587+
schedule_id: scheduleId,
13588+
timeslots: [{
13589+
start: timeString,
13590+
actions: [{ service, entity_id: item.id, service_data: serviceData }]
13591+
}],
13592+
name: `${item.name} - ${this.getActionLabel(action)} (${durationMinutes}min)`,
13593+
repeat_type: 'single'
13594+
});
13595+
console.log(`✅ Timer ${scheduleId} erfolgreich aktualisiert.`);
13596+
} catch (error) {
13597+
console.error(`❌ Fehler beim Aufruf von scheduler.edit:`, error);
13598+
alert(`Fehler beim Aktualisieren des Timers:\n\n${error.message}`);
13599+
}
13600+
}
1348513601

1348613602

1348713603

0 commit comments

Comments
 (0)