mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use attributes in demo media player (#78040)
This commit is contained in:
parent
e738df502b
commit
afe01c2434
@ -105,8 +105,8 @@ NETFLIX_PLAYER_SUPPORT = (
|
||||
class AbstractDemoPlayer(MediaPlayerEntity):
|
||||
"""A demo media players."""
|
||||
|
||||
_attr_sound_mode_list = SOUND_MODE_LIST
|
||||
_attr_should_poll = False
|
||||
_attr_sound_mode_list = SOUND_MODE_LIST
|
||||
|
||||
# We only implement the methods that we support
|
||||
|
||||
@ -185,6 +185,7 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
||||
|
||||
# We only implement the methods that we support
|
||||
|
||||
_attr_app_name = "YouTube"
|
||||
_attr_media_content_type = MediaType.MOVIE
|
||||
_attr_supported_features = YOUTUBE_PLAYER_SUPPORT
|
||||
|
||||
@ -193,36 +194,16 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
||||
) -> None:
|
||||
"""Initialize the demo device."""
|
||||
super().__init__(name)
|
||||
self.youtube_id = youtube_id
|
||||
self._media_title = media_title
|
||||
self._duration = duration
|
||||
self._attr_media_content_id = youtube_id
|
||||
self._attr_media_title = media_title
|
||||
self._attr_media_duration = duration
|
||||
self._progress: int | None = int(duration * 0.15)
|
||||
self._progress_updated_at = dt_util.utcnow()
|
||||
|
||||
@property
|
||||
def media_content_id(self) -> str:
|
||||
"""Return the content ID of current playing media."""
|
||||
return self.youtube_id
|
||||
|
||||
@property
|
||||
def media_duration(self) -> int:
|
||||
"""Return the duration of current playing media in seconds."""
|
||||
return self._duration
|
||||
|
||||
@property
|
||||
def media_image_url(self) -> str:
|
||||
"""Return the image url of current playing media."""
|
||||
return f"https://img.youtube.com/vi/{self.youtube_id}/hqdefault.jpg"
|
||||
|
||||
@property
|
||||
def media_title(self) -> str:
|
||||
"""Return the title of current playing media."""
|
||||
return self._media_title
|
||||
|
||||
@property
|
||||
def app_name(self) -> str:
|
||||
"""Return the current running application."""
|
||||
return "YouTube"
|
||||
return f"https://img.youtube.com/vi/{self.media_content_id}/hqdefault.jpg"
|
||||
|
||||
@property
|
||||
def media_position(self) -> int | None:
|
||||
@ -249,9 +230,11 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
||||
return self._progress_updated_at
|
||||
return None
|
||||
|
||||
def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None:
|
||||
def play_media(
|
||||
self, media_type: MediaType | str, media_id: str, **kwargs: Any
|
||||
) -> None:
|
||||
"""Play a piece of media."""
|
||||
self.youtube_id = media_id
|
||||
self._attr_media_content_id = media_id
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def media_pause(self) -> None:
|
||||
@ -266,7 +249,13 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
||||
|
||||
# We only implement the methods that we support
|
||||
|
||||
_attr_media_album_name = "Bounzz"
|
||||
_attr_media_content_id = "bounzz-1"
|
||||
_attr_media_content_type = MediaType.MUSIC
|
||||
_attr_media_duration = 213
|
||||
_attr_media_image_url = (
|
||||
"https://graph.facebook.com/v2.5/107771475912710/picture?type=large"
|
||||
)
|
||||
_attr_supported_features = MUSIC_PLAYER_SUPPORT
|
||||
|
||||
tracks = [
|
||||
@ -296,28 +285,8 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
||||
"""Initialize the demo device."""
|
||||
super().__init__(name)
|
||||
self._cur_track = 0
|
||||
self._group_members: list[str] = []
|
||||
self._repeat = RepeatMode.OFF
|
||||
|
||||
@property
|
||||
def group_members(self) -> list[str]:
|
||||
"""List of players which are currently grouped together."""
|
||||
return self._group_members
|
||||
|
||||
@property
|
||||
def media_content_id(self) -> str:
|
||||
"""Return the content ID of current playing media."""
|
||||
return "bounzz-1"
|
||||
|
||||
@property
|
||||
def media_duration(self) -> int:
|
||||
"""Return the duration of current playing media in seconds."""
|
||||
return 213
|
||||
|
||||
@property
|
||||
def media_image_url(self) -> str:
|
||||
"""Return the image url of current playing media."""
|
||||
return "https://graph.facebook.com/v2.5/107771475912710/picture?type=large"
|
||||
self._attr_group_members: list[str] = []
|
||||
self._attr_repeat = RepeatMode.OFF
|
||||
|
||||
@property
|
||||
def media_title(self) -> str:
|
||||
@ -329,21 +298,11 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
||||
"""Return the artist of current playing media (Music track only)."""
|
||||
return self.tracks[self._cur_track][0] if self.tracks else ""
|
||||
|
||||
@property
|
||||
def media_album_name(self) -> str:
|
||||
"""Return the album of current playing media (Music track only)."""
|
||||
return "Bounzz"
|
||||
|
||||
@property
|
||||
def media_track(self) -> int:
|
||||
"""Return the track number of current media (Music track only)."""
|
||||
return self._cur_track + 1
|
||||
|
||||
@property
|
||||
def repeat(self) -> RepeatMode:
|
||||
"""Return current repeat mode."""
|
||||
return self._repeat
|
||||
|
||||
def media_previous_track(self) -> None:
|
||||
"""Send previous track command."""
|
||||
if self._cur_track > 0:
|
||||
@ -365,28 +324,37 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
||||
|
||||
def set_repeat(self, repeat: RepeatMode) -> None:
|
||||
"""Enable/disable repeat mode."""
|
||||
self._repeat = repeat
|
||||
self._attr_repeat = repeat
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def join_players(self, group_members: list[str]) -> None:
|
||||
"""Join `group_members` as a player group with the current player."""
|
||||
self._group_members = [
|
||||
self._attr_group_members = [
|
||||
self.entity_id,
|
||||
] + group_members
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def unjoin_player(self) -> None:
|
||||
"""Remove this player from any group."""
|
||||
self._group_members = []
|
||||
self._attr_group_members = []
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
|
||||
class DemoTVShowPlayer(AbstractDemoPlayer):
|
||||
"""A Demo media player that only supports YouTube."""
|
||||
"""A Demo media player that only supports Netflix."""
|
||||
|
||||
# We only implement the methods that we support
|
||||
|
||||
_attr_app_name = "Netflix"
|
||||
_attr_media_content_id = "house-of-cards-1"
|
||||
_attr_media_content_type = MediaType.TVSHOW
|
||||
_attr_media_duration = 3600
|
||||
_attr_media_image_url = (
|
||||
"https://graph.facebook.com/v2.5/HouseofCards/picture?width=400"
|
||||
)
|
||||
_attr_media_season = "1"
|
||||
_attr_media_series_title = "House of Cards"
|
||||
_attr_source_list = ["dvd", "youtube"]
|
||||
_attr_supported_features = NETFLIX_PLAYER_SUPPORT
|
||||
|
||||
def __init__(self) -> None:
|
||||
@ -394,59 +362,18 @@ class DemoTVShowPlayer(AbstractDemoPlayer):
|
||||
super().__init__("Lounge room", MediaPlayerDeviceClass.TV)
|
||||
self._cur_episode = 1
|
||||
self._episode_count = 13
|
||||
self._source = "dvd"
|
||||
self._source_list = ["dvd", "youtube"]
|
||||
|
||||
@property
|
||||
def media_content_id(self) -> str:
|
||||
"""Return the content ID of current playing media."""
|
||||
return "house-of-cards-1"
|
||||
|
||||
@property
|
||||
def media_duration(self) -> int:
|
||||
"""Return the duration of current playing media in seconds."""
|
||||
return 3600
|
||||
|
||||
@property
|
||||
def media_image_url(self) -> str:
|
||||
"""Return the image url of current playing media."""
|
||||
return "https://graph.facebook.com/v2.5/HouseofCards/picture?width=400"
|
||||
self._attr_source = "dvd"
|
||||
|
||||
@property
|
||||
def media_title(self) -> str:
|
||||
"""Return the title of current playing media."""
|
||||
return f"Chapter {self._cur_episode}"
|
||||
|
||||
@property
|
||||
def media_series_title(self) -> str:
|
||||
"""Return the series title of current playing media (TV Show only)."""
|
||||
return "House of Cards"
|
||||
|
||||
@property
|
||||
def media_season(self) -> str:
|
||||
"""Return the season of current playing media (TV Show only)."""
|
||||
return "1"
|
||||
|
||||
@property
|
||||
def media_episode(self) -> str:
|
||||
"""Return the episode of current playing media (TV Show only)."""
|
||||
return str(self._cur_episode)
|
||||
|
||||
@property
|
||||
def app_name(self) -> str:
|
||||
"""Return the current running application."""
|
||||
return "Netflix"
|
||||
|
||||
@property
|
||||
def source(self) -> str:
|
||||
"""Return the current input source."""
|
||||
return self._source
|
||||
|
||||
@property
|
||||
def source_list(self) -> list[str]:
|
||||
"""List of available sources."""
|
||||
return self._source_list
|
||||
|
||||
def media_previous_track(self) -> None:
|
||||
"""Send previous track command."""
|
||||
if self._cur_episode > 1:
|
||||
@ -461,5 +388,5 @@ class DemoTVShowPlayer(AbstractDemoPlayer):
|
||||
|
||||
def select_source(self, source: str) -> None:
|
||||
"""Set the input source."""
|
||||
self._source = source
|
||||
self._attr_source = source
|
||||
self.schedule_update_ha_state()
|
||||
|
Loading…
x
Reference in New Issue
Block a user