Hotfix: Recently added and continue watching breaks whole card for old plex servers

pull/16/head
Juraj Nyíri 3 years ago
parent d78583a1d5
commit f245283f59

@ -19874,16 +19874,26 @@ class PlexMeetsHomeAssistant extends HTMLElement {
try { try {
if (this.plex) { if (this.plex) {
await this.plex.init(); await this.plex.init();
const continueWatching = await this.plex.getContinueWatching(); try {
const recentlyAdded = await this.plex.getRecentyAdded(); const continueWatching = await this.plex.getContinueWatching();
const recentlyAdded = await this.plex.getRecentyAdded();
this.data.Deck = continueWatching.Metadata;
this.data['Recently Added'] = recentlyAdded.Metadata;
}
catch (err) {
if (lodash.includes(err.message, 'Request failed with status code 404')) {
console.warn('PlexMeetsHomeAssistant: You are using outdated Plex server. Recently added and continue watching is not available.');
}
else {
throw err;
}
}
const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]); const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
this.data.serverID = serverID; this.data.serverID = serverID;
lodash.forEach(plexSections, section => { lodash.forEach(plexSections, section => {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
}); });
this.data.Deck = continueWatching.Metadata;
this.data['Recently Added'] = recentlyAdded.Metadata;
if (this.data[this.config.libraryName] === undefined) { if (this.data[this.config.libraryName] === undefined) {
this.error = `Library name ${this.config.libraryName} does not exist.`; this.error = `Library name ${this.config.libraryName} does not exist.`;
} }

@ -143,8 +143,21 @@ class PlexMeetsHomeAssistant extends HTMLElement {
try { try {
if (this.plex) { if (this.plex) {
await this.plex.init(); await this.plex.init();
const continueWatching = await this.plex.getContinueWatching(); try {
const recentlyAdded = await this.plex.getRecentyAdded(); const continueWatching = await this.plex.getContinueWatching();
const recentlyAdded = await this.plex.getRecentyAdded();
this.data.Deck = continueWatching.Metadata;
this.data['Recently Added'] = recentlyAdded.Metadata;
} catch (err) {
if (_.includes(err.message, 'Request failed with status code 404')) {
console.warn(
'PlexMeetsHomeAssistant: You are using outdated Plex server. Recently added and continue watching is not available.'
);
} else {
throw err;
}
}
const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]); const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
this.data.serverID = serverID; this.data.serverID = serverID;
@ -152,9 +165,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
}); });
this.data.Deck = continueWatching.Metadata;
this.data['Recently Added'] = recentlyAdded.Metadata;
if (this.data[this.config.libraryName] === undefined) { if (this.data[this.config.libraryName] === undefined) {
this.error = `Library name ${this.config.libraryName} does not exist.`; this.error = `Library name ${this.config.libraryName} does not exist.`;
} }

Loading…
Cancel
Save