Clean up Plex clip handling (#38500)

This commit is contained in:
jjlawren 2020-08-03 05:41:24 -05:00 committed by GitHub
parent 67312e2d42
commit e940811a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 16 deletions

View File

@ -10,6 +10,7 @@ from homeassistant.components.media_player.const import (
MEDIA_TYPE_MOVIE,
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_TVSHOW,
MEDIA_TYPE_VIDEO,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
@ -304,7 +305,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
self._state = STATE_OFF
def _set_media_type(self):
if self._session_type in ["clip", "episode"]:
if self._session_type == "episode":
self._media_content_type = MEDIA_TYPE_TVSHOW
# season number (00)
@ -334,6 +335,12 @@ class PlexMediaPlayer(MediaPlayerEntity):
)
self._media_artist = self._media_album_artist
elif self._session_type == "clip":
_LOGGER.debug(
"Clip content type detected, compatibility may vary: %s", self.name
)
self._media_content_type = MEDIA_TYPE_VIDEO
def force_idle(self):
"""Force client to idle."""
self._player_state = STATE_IDLE
@ -397,19 +404,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
@property
def media_content_type(self):
"""Return the content type of current playing media."""
if self._session_type == "clip":
_LOGGER.debug(
"Clip content type detected, compatibility may vary: %s", self.name
)
return MEDIA_TYPE_TVSHOW
if self._session_type == "episode":
return MEDIA_TYPE_TVSHOW
if self._session_type == "movie":
return MEDIA_TYPE_MOVIE
if self._session_type == "track":
return MEDIA_TYPE_MUSIC
return None
return self._media_content_type
@property
def media_artist(self):

View File

@ -82,7 +82,7 @@ class PlexSensor(Entity):
now_playing_user = f"{user} - {device}"
now_playing_title = ""
if sess.TYPE in ["clip", "episode"]:
if sess.TYPE == "episode":
# example:
# "Supernatural (2005) - s01e13 - Route 666"
@ -111,7 +111,7 @@ class PlexSensor(Entity):
track_album = sess.parentTitle
track_title = sess.title
now_playing_title = f"{track_artist} - {track_album} - {track_title}"
else:
elif sess.TYPE == "movie":
# example:
# "picture_of_last_summer_camp (2015)"
# "The Incredible Hulk (2008)"
@ -119,6 +119,8 @@ class PlexSensor(Entity):
year = await self.hass.async_add_executor_job(getattr, sess, "year")
if year is not None:
now_playing_title += f" ({year})"
else:
now_playing_title = sess.title
now_playing.append((now_playing_user, now_playing_title))
self._state = len(self.sessions)