Skip to content

Commit c83af1a

Browse files
committed
ignore non music sources in root
1 parent b8724ac commit c83af1a

File tree

15 files changed

+210
-129
lines changed

15 files changed

+210
-129
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ mediaBrowser:
296296
iconTitleBackgroundColor: blue # default is card background with opacity. Use this to change the background color of favorites icon titles.
297297
iconTitleColor: red # default is theme text color. Use this to change the color of favorites icon titles.
298298
numberToShow: 10 # Use this to limit the amount of favorites to show.
299-
replaceHttpWithHttpsForThumbnails: true # default is false. Use this if you want to replace http with https for thumbnails.
300299
sortByType: true # default is false. Will group favorites by type (e.g. radio, playlist, album).
301300
topItems: # Show these favorites at the top of the list
302301
- Legendary

scripts/sync-upstream.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ sed -i '' \
6363
-e 's|from "\.\./\.\./types"|from "../../types"|g' \
6464
"$UPSTREAM_DIR/ha-media-player-browse.ts"
6565

66+
# Use filterOutIgnoredMediaSources to filter children
67+
echo "Adding media source filter..."
68+
sed -i '' 's/let children = currentItem.children || \[\];/let children = filterOutIgnoredMediaSources(currentItem.children || []);/g' \
69+
"$UPSTREAM_DIR/ha-media-player-browse.ts"
70+
6671
# CRITICAL: Rename component to avoid registration conflicts with HA frontend
6772
echo "Renaming component to avoid conflicts..."
6873
sed -i '' 's/@customElement("ha-media-player-browse")/@customElement("sonos-ha-media-player-browse")/g' \
@@ -91,6 +96,11 @@ sed -i '' \
9196
echo "$RELEASE_TAG" > "$VERSION_FILE"
9297
echo "Synced: $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> "$VERSION_FILE"
9398

99+
# Add filterOutIgnoredMediaSources import to ha-media-player-browse.ts
100+
echo "Adding filterOutIgnoredMediaSources import..."
101+
sed -i '' '1s/^/import { filterOutIgnoredMediaSources } from '\''..\/utils\/media-browse-utils'\'';\n/' \
102+
"$UPSTREAM_DIR/ha-media-player-browse.ts"
103+
94104
# Add @ts-nocheck to all upstream TypeScript files
95105
echo "Adding @ts-nocheck to all upstream files..."
96106
for file in $(find "$UPSTREAM_DIR" -name "*.ts" -type f); do
@@ -103,6 +113,7 @@ echo ""
103113
echo "✅ Synced from HA frontend release: $RELEASE_TAG"
104114
echo "✅ Component renamed to 'sonos-ha-media-player-browse'"
105115
echo "✅ Grid customizations applied (100px items, 8px gap)"
116+
echo "✅ Non-audio media sources filtered (TTS, camera, images)"
106117
echo "✅ @ts-nocheck added to all upstream files"
107118
echo "✅ Version saved to $VERSION_FILE"
108119
echo ""

src/components/favorites-icons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Store from '../model/store';
44
import { FavoritesConfig, MediaBrowserConfig, MediaPlayerItem } from '../types';
55
import { customEvent } from '../utils/utils';
66
import { MEDIA_ITEM_SELECTED, mediaItemTitleStyle } from '../constants';
7-
import { itemsWithFallbacks, renderFavoritesItem } from '../utils/favorites-utils';
7+
import { itemsWithFallbacks, renderFavoritesItem } from '../utils/media-browse-utils';
88
import { styleMap } from 'lit-html/directives/style-map.js';
99

1010
export class FavoritesIcons extends LitElement {

src/components/favorites-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Store from '../model/store';
44
import { CardConfig, MediaPlayerItem } from '../types';
55
import { customEvent } from '../utils/utils';
66
import { listStyle, MEDIA_ITEM_SELECTED } from '../constants';
7-
import { itemsWithFallbacks } from '../utils/favorites-utils';
7+
import { itemsWithFallbacks } from '../utils/media-browse-utils';
88

99
export class FavoritesList extends LitElement {
1010
@property({ attribute: false }) store!: Store;

src/components/media-row.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { property } from 'lit/decorators.js';
33
import Store from '../model/store';
44
import { MediaPlayerItem } from '../types';
55
import { mediaItemTitleStyle } from '../constants';
6-
import { renderFavoritesItem } from '../utils/favorites-utils';
6+
import { renderFavoritesItem } from '../utils/media-browse-utils';
77
import './playing-bars';
88

99
class MediaRow extends LitElement {

src/editor/editor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class CardEditor extends BaseEditor {
6363
};
6464

6565
protected render(): TemplateResult {
66+
if (!this.config) {
67+
return html``;
68+
}
6669
if (!this.config.sections || this.config.sections.length === 0) {
6770
this.config.sections = [Section.PLAYER, Section.VOLUMES, Section.GROUPS, Section.GROUPING, Section.MEDIA_BROWSER];
6871
if (isSonosCard(this.config)) {
@@ -83,15 +86,15 @@ class CardEditor extends BaseEditor {
8386
></ha-icon-button>
8487
<div class="tabs-list">
8588
${tabs.map(
86-
(tab) => html`
89+
(tab) => html`
8790
<button
8891
class="tab-button ${this.activeTab === tab ? 'active' : ''}"
8992
@click=${() => (this.activeTab = tab)}
9093
>
9194
${tab}
9295
</button>
9396
`,
94-
)}
97+
)}
9598
</div>
9699
<ha-icon-button
97100
class="nav-arrow ${showRightArrow ? '' : 'hidden'}"
Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,64 @@
11
export const MEDIA_BROWSER_SCHEMA = [
2-
{
3-
name: 'hideHeader',
4-
selector: { boolean: {} },
5-
},
6-
{
7-
name: 'itemsPerRow',
8-
type: 'integer',
9-
valueMin: 1,
10-
},
11-
{
12-
name: 'onlyFavorites',
13-
selector: { boolean: {} },
14-
},
2+
{
3+
name: 'hideHeader',
4+
selector: { boolean: {} },
5+
},
6+
{
7+
name: 'itemsPerRow',
8+
type: 'integer',
9+
valueMin: 1,
10+
},
11+
{
12+
name: 'onlyFavorites',
13+
selector: { boolean: {} },
14+
},
1515
];
1616

1717
export const FAVORITES_SUB_SCHEMA = [
18-
{
19-
name: 'title',
20-
type: 'string',
21-
},
22-
{
23-
name: 'exclude',
24-
type: 'string',
25-
},
26-
{
27-
name: 'hideTitleForThumbnailIcons',
28-
selector: { boolean: {} },
29-
},
30-
{
31-
name: 'iconBorder',
32-
type: 'string',
33-
help: 'Border for favorites icons (e.g., 1px solid white)',
34-
},
35-
{
36-
name: 'iconPadding',
37-
type: 'float',
38-
help: 'Padding around favorites icon artwork (rem)',
39-
valueMin: 0,
40-
},
41-
{
42-
name: 'iconTitleBackgroundColor',
43-
type: 'string',
44-
help: 'Background color for favorites icon titles',
45-
},
46-
{
47-
name: 'iconTitleColor',
48-
type: 'string',
49-
help: 'Color for favorites icon titles (e.g., red, #ff0000)',
50-
},
51-
{
52-
name: 'numberToShow',
53-
type: 'integer',
54-
valueMin: 1,
55-
},
56-
{
57-
name: 'replaceHttpWithHttpsForThumbnails',
58-
selector: { boolean: {} },
59-
},
60-
{
61-
name: 'sortByType',
62-
selector: { boolean: {} },
63-
},
64-
{
65-
name: 'topItems',
66-
type: 'string',
67-
},
18+
{
19+
name: 'title',
20+
type: 'string',
21+
},
22+
{
23+
name: 'exclude',
24+
type: 'string',
25+
},
26+
{
27+
name: 'hideTitleForThumbnailIcons',
28+
selector: { boolean: {} },
29+
},
30+
{
31+
name: 'iconBorder',
32+
type: 'string',
33+
help: 'Border for favorites icons (e.g., 1px solid white)',
34+
},
35+
{
36+
name: 'iconPadding',
37+
type: 'float',
38+
help: 'Padding around favorites icon artwork (rem)',
39+
valueMin: 0,
40+
},
41+
{
42+
name: 'iconTitleBackgroundColor',
43+
type: 'string',
44+
help: 'Background color for favorites icon titles',
45+
},
46+
{
47+
name: 'iconTitleColor',
48+
type: 'string',
49+
help: 'Color for favorites icon titles (e.g., red, #ff0000)',
50+
},
51+
{
52+
name: 'numberToShow',
53+
type: 'integer',
54+
valueMin: 1,
55+
},
56+
{
57+
name: 'sortByType',
58+
selector: { boolean: {} },
59+
},
60+
{
61+
name: 'topItems',
62+
type: 'string',
63+
},
6864
];

src/model/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export default class Store {
5151
[],
5252
);
5353
this.activePlayer = this.determineActivePlayer(activePlayerId);
54-
this.hassService = new HassService(this.hass, currentSection, card, config);
54+
this.hassService = new HassService(this.hass, currentSection, card);
5555
this.mediaControlService = new MediaControlService(this.hassService, config);
56-
this.mediaBrowseService = new MediaBrowseService(this.hassService, config);
56+
this.mediaBrowseService = new MediaBrowseService(this.hass, config);
5757
this.predefinedGroups = this.createPredefinedGroups();
5858
}
5959

src/sections/media-browser.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { MEDIA_ITEM_SELECTED } from '../constants';
1919
import { customEvent } from '../utils/utils';
2020
import { FavoritesConfig, MediaBrowserConfig, MediaPlayerItem } from '../types';
2121
import { until } from 'lit-html/directives/until.js';
22-
import { indexOfWithoutSpecialChars } from '../utils/favorites-utils';
22+
import { indexOfWithoutSpecialChars } from '../utils/media-browse-utils';
2323

2424
type LayoutType = 'auto' | 'grid' | 'list';
2525
type ViewType = 'favorites' | 'browser';
@@ -180,8 +180,8 @@ export class MediaBrowser extends LitElement {
180180
<div class="spacer"></div>
181181
<span class="title">${title}</span>
182182
${onlyFavorites
183-
? ''
184-
: html`<ha-icon-button
183+
? ''
184+
: html`<ha-icon-button
185185
.path=${mdiPlayBoxMultiple}
186186
@click=${this.goToBrowser}
187187
title="Browse Media"
@@ -231,32 +231,32 @@ export class MediaBrowser extends LitElement {
231231

232232
return html`
233233
${until(
234-
this.getFavorites()
235-
.then((items) => {
236-
if (items?.length) {
237-
if (useGrid) {
238-
return html`
234+
this.getFavorites()
235+
.then((items) => {
236+
if (items?.length) {
237+
if (useGrid) {
238+
return html`
239239
<sonos-favorites-icons
240240
.items=${items}
241241
.store=${this.store}
242242
@item-selected=${this.onFavoriteSelected}
243243
></sonos-favorites-icons>
244244
`;
245-
} else {
246-
return html`
245+
} else {
246+
return html`
247247
<sonos-favorites-list
248248
.items=${items}
249249
.store=${this.store}
250250
@item-selected=${this.onFavoriteSelected}
251251
></sonos-favorites-list>
252252
`;
253-
}
254-
} else {
255-
return html`<div class="no-items">No favorites found</div>`;
256253
}
257-
})
258-
.catch((e) => html`<div class="no-items">Failed to fetch favorites. ${e.message ?? JSON.stringify(e)}</div>`),
259-
)}
254+
} else {
255+
return html`<div class="no-items">No favorites found</div>`;
256+
}
257+
})
258+
.catch((e) => html`<div class="no-items">Failed to fetch favorites. ${e.message ?? JSON.stringify(e)}</div>`),
259+
)}
260260
`;
261261
}
262262

@@ -318,8 +318,8 @@ export class MediaBrowser extends LitElement {
318318
? ''
319319
: html`<div class="header">
320320
${canGoBack
321-
? html`<ha-icon-button .path=${mdiArrowLeft} @click=${this.goBack}></ha-icon-button>`
322-
: html`<div class="spacer"></div>`}
321+
? html`<ha-icon-button .path=${mdiArrowLeft} @click=${this.goBack}></ha-icon-button>`
322+
: html`<div class="spacer"></div>`}
323323
<span class="title">${title}</span>
324324
<ha-icon-button .path=${mdiStar} @click=${this.goToFavorites} title="Favorites"></ha-icon-button>
325325
<ha-icon-button

src/services/hass-service.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HomeAssistant } from 'custom-card-helpers';
2-
import { CardConfig, GetQueueResponse, MediaPlayerItem, Section, TemplateResult } from '../types';
2+
import { GetQueueResponse, MediaPlayerItem, Section, TemplateResult } from '../types';
33
import { ServiceCallRequest } from 'custom-card-helpers/dist/types';
44
import { CALL_MEDIA_DONE, CALL_MEDIA_STARTED } from '../constants';
55
import { MediaPlayer } from '../model/media-player';
@@ -9,13 +9,11 @@ export default class HassService {
99
private readonly hass: HomeAssistant;
1010
private readonly currentSection: Section;
1111
private readonly card: Element;
12-
private readonly config: CardConfig;
1312

14-
constructor(hass: HomeAssistant, section: Section, card: Element, config: CardConfig) {
13+
constructor(hass: HomeAssistant, section: Section, card: Element) {
1514
this.hass = hass;
1615
this.currentSection = section;
1716
this.card = card;
18-
this.config = config;
1917
}
2018

2119
async callMediaService(service: string, inOptions: ServiceCallRequest['serviceData']) {
@@ -27,22 +25,6 @@ export default class HassService {
2725
}
2826
}
2927

30-
async browseMedia(mediaPlayer: MediaPlayer, media_content_type?: string, media_content_id?: string) {
31-
const mediaPlayerItem = await this.hass.callWS<MediaPlayerItem>({
32-
type: 'media_player/browse_media',
33-
entity_id: mediaPlayer.id,
34-
media_content_id,
35-
media_content_type,
36-
});
37-
if (this.config.mediaBrowser?.favorites?.replaceHttpWithHttpsForThumbnails) {
38-
mediaPlayerItem.children = mediaPlayerItem.children?.map((child) => ({
39-
...child,
40-
thumbnail: child.thumbnail?.replace('http://', 'https://'),
41-
}));
42-
}
43-
return mediaPlayerItem;
44-
}
45-
4628
async renderTemplate<T>(template: string, defaultValue: T): Promise<T> {
4729
return new Promise<T>((resolve) => {
4830
const subscribeMessage = {

0 commit comments

Comments
 (0)