Skip to content

Commit f15a0a9

Browse files
authored
Update fast-search-card.js
1 parent 5befb1e commit f15a0a9

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

dist/fast-search-card.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7867,13 +7867,16 @@ class FastSearchCard extends HTMLElement {
78677867
const isOn = !['off', 'unavailable'].includes(state.state);
78687868
this.callClimateService(isOn ? 'turn_off' : 'turn_on', item.id);
78697869
}
7870-
break;
7871-
7870+
break;
7871+
78727872
case 'media_player':
78737873
if (action === 'play-pause') {
7874-
this.callMusicAssistantService('media_play_pause', item.id);
7874+
const state = this.hass.states[item.id];
7875+
const isPlaying = state?.state === 'playing';
7876+
const service = isPlaying ? 'media_pause' : 'media_play';
7877+
this.hass.callService('media_player', service, { entity_id: item.id });
78757878
}
7876-
break;
7879+
break;
78777880

78787881
case 'cover':
78797882
switch (action) {
@@ -7903,18 +7906,20 @@ class FastSearchCard extends HTMLElement {
79037906
case 'climate':
79047907
button.title = isActive ? 'Ausschalten' : 'Einschalten';
79057908
break;
7906-
7909+
79077910
case 'media_player':
79087911
const isPlaying = state.state === 'playing';
7912+
const isUnavailable = ['unavailable', 'unknown', 'off'].includes(state.state);
7913+
79097914
button.classList.toggle('active', isPlaying);
7910-
button.title = isPlaying ? 'Pause' : 'Play';
7915+
button.disabled = isUnavailable;
7916+
button.title = isUnavailable ? 'Nicht verfügbar' : (isPlaying ? 'Pause' : 'Play');
79117917

7912-
// Update icon
79137918
const playIcon = `<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.90588 4.53682C6.50592 4.2998 6 4.58808 6 5.05299V18.947C6 19.4119 6.50592 19.7002 6.90588 19.4632L18.629 12.5162C19.0211 12.2838 19.0211 11.7162 18.629 11.4838L6.90588 4.53682Z" stroke="currentColor"></path></svg>`;
79147919
const pauseIcon = `<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6 18.4V5.6C6 5.26863 6.26863 5 6.6 5H9.4C9.73137 5 10 5.26863 10 5.6V18.4C10 18.7314 9.73137 19 9.4 19H6.6C6.26863 19 6 18.7314 6 18.4Z" stroke="currentColor"></path><path d="M14 18.4V5.6C14 5.26863 14.2686 5 14.6 5H17.4C17.7314 5 18 5.26863 18 5.6V18.4C18 18.7314 17.7314 19 17.4 19H14.6C14.2686 19 14 18.7314 14 18.4Z" stroke="currentColor"></path></svg>`;
79157920

79167921
button.innerHTML = isPlaying ? pauseIcon : playIcon;
7917-
break;
7922+
break;
79187923

79197924
case 'cover':
79207925
const position = state.attributes.current_position ?? 0;
@@ -11883,14 +11888,19 @@ class FastSearchCard extends HTMLElement {
1188311888
// Update play/pause button
1188411889
const playPauseBtn = mediaContainer.querySelector('[data-action="play-pause"]');
1188511890
if (playPauseBtn) {
11886-
playPauseBtn.classList.remove('active');
11891+
playPauseBtn.classList.toggle('active', isPlaying);
11892+
playPauseBtn.disabled = ['unavailable', 'unknown', 'off'].includes(state.state);
1188711893
playPauseBtn.title = isPlaying ? 'Pause' : 'Play';
1188811894

11889-
// Update icon
1189011895
const iconHTML = isPlaying ? `
11891-
<svg width="48px" height="48px" stroke-width="1" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor"><path d="M6 18.4V5.6C6 5.26863 6.26863 5 6.6 5H9.4C9.73137 5 10 5.26863 10 5.6V18.4C10 18.7314 9.73137 19 9.4 19H6.6C6.26863 19 6 18.7314 6 18.4Z" stroke="currentColor" stroke-width="1"></path><path d="M14 18.4V5.6C14 5.26863 14.2686 5 14.6 5H17.4C17.7314 5 18 5.26863 18 5.6V18.4C18 18.7314 17.7314 19 17.4 19H14.6C14.2686 19 14 18.7314 14 18.4Z" stroke="currentColor" stroke-width="1"></path></svg>
11896+
<svg width="48px" height="48px" stroke-width="1" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor">
11897+
<path d="M6 18.4V5.6C6 5.26863 6.26863 5 6.6 5H9.4C9.73137 5 10 5.26863 10 5.6V18.4C10 18.7314 9.73137 19 9.4 19H6.6C6.26863 19 6 18.7314 6 18.4Z" stroke="currentColor" stroke-width="1"></path>
11898+
<path d="M14 18.4V5.6C14 5.26863 14.2686 5 14.6 5H17.4C17.7314 5 18 5.26863 18 5.6V18.4C18 18.7314 17.7314 19 17.4 19H14.6C14.2686 19 14 18.7314 14 18.4Z" stroke="currentColor" stroke-width="1"></path>
11899+
</svg>
1189211900
` : `
11893-
<svg width="48px" height="48px" stroke-width="1" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor"><path d="M6.90588 4.53682C6.50592 4.2998 6 4.58808 6 5.05299V18.947C6 19.4119 6.50592 19.7002 6.90588 19.4632L18.629 12.5162C19.0211 12.2838 19.0211 11.7162 18.629 11.4838L6.90588 4.53682Z" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"></path></svg>
11901+
<svg width="48px" height="48px" stroke-width="1" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="currentColor">
11902+
<path d="M6.90588 4.53682C6.50592 4.2998 6 4.58808 6 5.05299V18.947C6 19.4119 6.50592 19.7002 6.90588 19.4632L18.629 12.5162C19.0211 12.2838 19.0211 11.7162 18.629 11.4838L6.90588 4.53682Z" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"></path>
11903+
</svg>
1189411904
`;
1189511905
playPauseBtn.innerHTML = iconHTML;
1189611906
}
@@ -12093,7 +12103,18 @@ class FastSearchCard extends HTMLElement {
1209312103
console.log('TTS Button:', ttsBtn);
1209412104

1209512105
if (prevBtn) prevBtn.addEventListener('click', () => this.callMusicAssistantService('media_previous_track', item.id));
12096-
if (playPauseBtn) playPauseBtn.addEventListener('click', () => this.callMusicAssistantService('media_play_pause', item.id));
12106+
12107+
if (playPauseBtn) {
12108+
playPauseBtn.addEventListener('click', (e) => {
12109+
e.preventDefault();
12110+
e.stopPropagation();
12111+
const state = this.hass.states[item.id];
12112+
const isPlaying = state?.state === 'playing';
12113+
const service = isPlaying ? 'media_pause' : 'media_play';
12114+
this.hass.callService('media_player', service, { entity_id: item.id });
12115+
});
12116+
}
12117+
1209712118
if (nextBtn) nextBtn.addEventListener('click', () => this.callMusicAssistantService('media_next_track', item.id));
1209812119

1209912120
// Music Assistant Toggle

0 commit comments

Comments
 (0)