Skip to content

Commit

Permalink
debug no favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Dec 15, 2023
1 parent 9955a56 commit 90dec35
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ export class Card extends LitElement {
const newEntityId = (event as CustomEvent).detail.entityId;
if (newEntityId !== this.activePlayerId) {
this.activePlayerId = newEntityId;
this.requestUpdate();
try {
this.requestUpdate();
} catch (e) {
console.error('Error updating card. newEntityId:',newEntityId);
console.error(e);
}
}
};

Expand Down
7 changes: 6 additions & 1 deletion src/editor/base-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export abstract class BaseEditor extends LitElement {

protected configChanged() {
fireEvent(this, 'config-changed', { config: this.config });
this.requestUpdate();
try {
this.requestUpdate();
} catch (e) {
console.error('config changed');
console.error(e);
}
}
protected dispatchClose() {
return this.dispatchEvent(new CustomEvent('closed'));
Expand Down
2 changes: 2 additions & 0 deletions src/sections/media-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export class MediaBrowser extends LitElement {
...(this.config.customSources?.all?.map(MediaBrowser.createSource) || []),
...allFavorites,
];
console.log('Custom Sonos Card: allFavorites', allFavorites);
allFavorites = this.config.numberOfFavoritesToShow
? allFavorites.slice(0, this.config.numberOfFavoritesToShow)
: allFavorites;
console.log('Custom Sonos Card: allFavorites after slicing', allFavorites);
return allFavorites;
}

Expand Down
7 changes: 6 additions & 1 deletion src/sections/volumes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class Volumes extends LitElement {
}
private toggleShowSwitches(player: MediaPlayer) {
this.showSwitches[player.id] = !this.showSwitches[player.id];
this.requestUpdate();
try {
this.requestUpdate();
} catch (e) {
console.error('Error updating volumes');
console.error(e);
}
}

private async getAdditionalControls(hide: boolean, player: MediaPlayer) {
Expand Down
9 changes: 8 additions & 1 deletion src/services/media-browse-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ export default class MediaBrowseService {
}

async getAllFavorites(mediaPlayers: MediaPlayer[], ignoredTitles?: string[]): Promise<MediaPlayerItem[]> {
console.log('Custom Sonos Card: getting all favorites', mediaPlayers, ignoredTitles);
if (!mediaPlayers.length) {
return [];
}
const favoritesForAllPlayers = await Promise.all(mediaPlayers.map((player) => this.getFavoritesForPlayer(player)));
console.log('Custom Sonos Card: favoritesForAllPlayers', favoritesForAllPlayers);
let favorites = favoritesForAllPlayers.flatMap((f) => f);
console.log('Custom Sonos Card: favorites', favorites);
favorites = this.removeDuplicates(favorites);
console.log('Custom Sonos Card: favorites after removing duplicates', favorites);
favorites = favorites.length ? favorites : this.getFavoritesFromStates(mediaPlayers);
return favorites.filter((item) => indexOfWithoutSpecialChars(ignoredTitles ?? [], item.title) === -1);
console.log('Custom Sonos Card: favorites after getting from states', favorites);
const filtered = favorites.filter((item) => indexOfWithoutSpecialChars(ignoredTitles ?? [], item.title) === -1);
console.log('Custom Sonos Card: favorites after filtering', filtered);
return filtered;
}

private removeDuplicates(items: MediaPlayerItem[]) {
Expand Down

0 comments on commit 90dec35

Please sign in to comment.