Fix: Handle case where cast through plex player fails

2.0
Juraj Nyíri 3 years ago
parent 5a780bec45
commit cc86583fc7

@ -18909,16 +18909,17 @@ class PlayController {
break; break;
case 'cast': case 'cast':
if (this.hass.services.plex) { if (this.hass.services.plex) {
try {
switch (data.type) { switch (data.type) {
case 'movie': case 'movie':
this.playViaCastPlex(entity.value, 'movie', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'movie', `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: data.librarySectionTitle, library_name: data.librarySectionTitle,
title: data.title title: data.title
})}`); })}`);
break; break;
case 'episode': case 'episode':
this.playViaCastPlex(entity.value, 'EPISODE', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'EPISODE', `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: data.librarySectionTitle, library_name: data.librarySectionTitle,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -18933,6 +18934,11 @@ class PlayController {
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, data.Media[0].Part[0].key);
} }
} }
catch (err) {
console.log(err);
this.playViaCast(entity.value, data.Media[0].Part[0].key);
}
}
else { else {
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, data.Media[0].Part[0].key);
} }
@ -19070,7 +19076,7 @@ class PlayController {
}); });
}; };
this.playViaCastPlex = (entityName, contentType, mediaLink) => { this.playViaCastPlex = (entityName, contentType, mediaLink) => {
this.hass.callService('media_player', 'play_media', { return this.hass.callService('media_player', 'play_media', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName, entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase

@ -112,9 +112,10 @@ class PlayController {
break; break;
case 'cast': case 'cast':
if (this.hass.services.plex) { if (this.hass.services.plex) {
try {
switch (data.type) { switch (data.type) {
case 'movie': case 'movie':
this.playViaCastPlex( await this.playViaCastPlex(
entity.value, entity.value,
'movie', 'movie',
`plex://${JSON.stringify({ `plex://${JSON.stringify({
@ -125,7 +126,7 @@ class PlayController {
); );
break; break;
case 'episode': case 'episode':
this.playViaCastPlex( await this.playViaCastPlex(
entity.value, entity.value,
'EPISODE', 'EPISODE',
`plex://${JSON.stringify({ `plex://${JSON.stringify({
@ -143,6 +144,10 @@ class PlayController {
default: default:
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, data.Media[0].Part[0].key);
} }
} catch (err) {
console.log(err);
this.playViaCast(entity.value, data.Media[0].Part[0].key);
}
} else { } else {
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, data.Media[0].Part[0].key);
} }
@ -287,8 +292,8 @@ class PlayController {
}); });
}; };
private playViaCastPlex = (entityName: string, contentType: string, mediaLink: string): void => { private playViaCastPlex = (entityName: string, contentType: string, mediaLink: string): Promise<void> => {
this.hass.callService('media_player', 'play_media', { return this.hass.callService('media_player', 'play_media', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName, entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase

Loading…
Cancel
Save