File tree Expand file tree Collapse file tree 3 files changed +38
-41
lines changed
Expand file tree Collapse file tree 3 files changed +38
-41
lines changed Original file line number Diff line number Diff line change @@ -31,30 +31,32 @@ export class MediaBrowser extends LitElement {
3131
3232 ${ this . activePlayer &&
3333 until (
34- this . getFavorites ( this . activePlayer ) . then ( ( items ) => {
35- if ( items ?. length ) {
36- const itemsPerRow = this . config . favoritesItemsPerRow || 4 ;
37- if ( itemsPerRow > 1 ) {
38- return html `
39- <sonos- media- browser- icons
40- .items = ${ items }
41- .store = ${ this . store }
42- @item-selected = ${ this . onMediaItemSelected }
43- > </ sonos- media- browser- icons>
44- ` ;
34+ this . getFavorites ( this . activePlayer )
35+ . then ( ( items ) => {
36+ if ( items ?. length ) {
37+ const itemsPerRow = this . config . favoritesItemsPerRow || 4 ;
38+ if ( itemsPerRow > 1 ) {
39+ return html `
40+ <sonos- media- browser- icons
41+ .items = ${ items }
42+ .store = ${ this . store }
43+ @item-selected = ${ this . onMediaItemSelected }
44+ > </ sonos- media- browser- icons>
45+ ` ;
46+ } else {
47+ return html `
48+ <sonos- media- browser- lis t
49+ .items = ${ items }
50+ .store = ${ this . store }
51+ @item-selected = ${ this . onMediaItemSelected }
52+ > </ sonos- media- browser- lis t>
53+ ` ;
54+ }
4555 } else {
46- return html `
47- <sonos- media- browser- lis t
48- .items = ${ items }
49- .store = ${ this . store }
50- @item-selected = ${ this . onMediaItemSelected }
51- > </ sonos- media- browser- lis t>
52- ` ;
56+ return html `<div class= "no-items" > No favorites found </ div> ` ;
5357 }
54- } else {
55- return html `<div class= "no-items" > No favorites found </ div> ` ;
56- }
57- } ) ,
58+ } )
59+ . catch ( ( e ) => html `<div class= "no-items" > Failed to fetch list of favorites . ${ e } </ div> ` ) ,
5860 ) }
5961 ` ;
6062 }
Original file line number Diff line number Diff line change @@ -35,25 +35,20 @@ export default class MediaBrowseService {
3535 }
3636
3737 private async getFavoritesForPlayer ( player : MediaPlayer ) {
38- try {
39- const mediaRoot = await this . hassService . browseMedia ( player ) ;
40- const favoritesStr = 'favorites' ;
41- const favoritesDir = mediaRoot . children ?. find (
42- ( child ) =>
43- child . media_content_type ?. toLowerCase ( ) === favoritesStr ||
44- child . media_content_id ?. toLowerCase ( ) === favoritesStr ||
45- child . title . toLowerCase ( ) === favoritesStr ,
46- ) ;
47- if ( ! favoritesDir ) {
48- return [ ] ;
49- }
50- const favorites : MediaPlayerItem [ ] = [ ] ;
51- await this . browseDir ( player , favoritesDir , favorites ) ;
52- return favorites ;
53- } catch ( e ) {
54- console . error ( `Sonos Card: error getting favorites for player ${ player . id } : ${ JSON . stringify ( e ) } ` ) ;
38+ const mediaRoot = await this . hassService . browseMedia ( player ) ;
39+ const favoritesStr = 'favorites' ;
40+ const favoritesDir = mediaRoot . children ?. find (
41+ ( child ) =>
42+ child . media_content_type ?. toLowerCase ( ) === favoritesStr ||
43+ child . media_content_id ?. toLowerCase ( ) === favoritesStr ||
44+ child . title . toLowerCase ( ) === favoritesStr ,
45+ ) ;
46+ if ( ! favoritesDir ) {
5547 return [ ] ;
5648 }
49+ const favorites : MediaPlayerItem [ ] = [ ] ;
50+ await this . browseDir ( player , favoritesDir , favorites ) ;
51+ return favorites ;
5752 }
5853
5954 private async browseDir ( player : MediaPlayer , favoritesDir : MediaPlayerItem , favorites : MediaPlayerItem [ ] ) {
Original file line number Diff line number Diff line change @@ -128,8 +128,8 @@ export interface CustomFavoriteThumbnails {
128128}
129129
130130export interface MediaPlayerItem {
131- can_play : boolean ;
132- can_expand : boolean ;
131+ can_play ? : boolean ;
132+ can_expand ? : boolean ;
133133 title : string ;
134134 thumbnail ?: string ;
135135 children ?: MediaPlayerItem [ ] ;
You can’t perform that action at this time.
0 commit comments