Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Dec 17, 2023
1 parent 90dec35 commit 203c4a1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/services/media-browse-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class MediaBrowseService {
if (!mediaPlayers.length) {
return [];
}
console.log('Custom Sonos Card: getting favorites for all players');
const favoritesForAllPlayers = await Promise.all(mediaPlayers.map((player) => this.getFavoritesForPlayer(player)));
console.log('Custom Sonos Card: favoritesForAllPlayers', favoritesForAllPlayers);
let favorites = favoritesForAllPlayers.flatMap((f) => f);
Expand All @@ -35,12 +36,17 @@ export default class MediaBrowseService {
}

private async getFavoritesForPlayer(player: MediaPlayer) {
console.log('Custom Sonos Card: getting favorites for player', player.id);
const favoritesRoot = await this.hassService.browseMedia(player, 'favorites', '');
console.log('Custom Sonos Card: favoritesRoot', favoritesRoot.media_content_id);
const favoriteTypesPromise = favoritesRoot.children?.map((favoriteItem) =>
this.hassService.browseMedia(player, favoriteItem.media_content_type, favoriteItem.media_content_id),
);
const favoriteTypes = favoriteTypesPromise ? await Promise.all(favoriteTypesPromise) : [];
return favoriteTypes.flatMap((item) => item.children ?? []);
console.log('Custom Sonos Card: favoriteTypes', favoriteTypes.length);
const mediaPlayerItems = favoriteTypes.flatMap((item) => item.children ?? []);
console.log('Custom Sonos Card: mediaPlayerItems', mediaPlayerItems.length);
return mediaPlayerItems;
}

private getFavoritesFromStates(mediaPlayers: MediaPlayer[]) {
Expand Down

0 comments on commit 203c4a1

Please sign in to comment.