diff --git a/homeassistant/components/plex/media_player.py b/homeassistant/components/plex/media_player.py index d467b962da..1b7db505e2 100644 --- a/homeassistant/components/plex/media_player.py +++ b/homeassistant/components/plex/media_player.py @@ -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): diff --git a/homeassistant/components/plex/sensor.py b/homeassistant/components/plex/sensor.py index 47d12fb35d..a3b465dfdb 100644 --- a/homeassistant/components/plex/sensor.py +++ b/homeassistant/components/plex/sensor.py @@ -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)