mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use new media player enums in demo (#78114)
* Use new media player enums in demo * Adjust import location
This commit is contained in:
parent
9a61cc07c7
commit
b0777e6280
@ -7,16 +7,12 @@ from typing import Any
|
|||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MediaPlayerDeviceClass,
|
MediaPlayerDeviceClass,
|
||||||
MediaPlayerEntity,
|
MediaPlayerEntity,
|
||||||
)
|
|
||||||
from homeassistant.components.media_player.const import (
|
|
||||||
MEDIA_TYPE_MOVIE,
|
|
||||||
MEDIA_TYPE_MUSIC,
|
|
||||||
MEDIA_TYPE_TVSHOW,
|
|
||||||
REPEAT_MODE_OFF,
|
|
||||||
MediaPlayerEntityFeature,
|
MediaPlayerEntityFeature,
|
||||||
|
MediaPlayerState,
|
||||||
|
MediaType,
|
||||||
|
RepeatMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import STATE_OFF, STATE_PAUSED, STATE_PLAYING
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
@ -118,7 +114,7 @@ class AbstractDemoPlayer(MediaPlayerEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the demo device."""
|
"""Initialize the demo device."""
|
||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
self._player_state = STATE_PLAYING
|
self._player_state = MediaPlayerState.PLAYING
|
||||||
self._volume_level = 1.0
|
self._volume_level = 1.0
|
||||||
self._volume_muted = False
|
self._volume_muted = False
|
||||||
self._shuffle = False
|
self._shuffle = False
|
||||||
@ -163,12 +159,12 @@ class AbstractDemoPlayer(MediaPlayerEntity):
|
|||||||
|
|
||||||
def turn_on(self) -> None:
|
def turn_on(self) -> None:
|
||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
self._player_state = STATE_PLAYING
|
self._player_state = MediaPlayerState.PLAYING
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_off(self) -> None:
|
def turn_off(self) -> None:
|
||||||
"""Turn the media player off."""
|
"""Turn the media player off."""
|
||||||
self._player_state = STATE_OFF
|
self._player_state = MediaPlayerState.OFF
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def mute_volume(self, mute: bool) -> None:
|
def mute_volume(self, mute: bool) -> None:
|
||||||
@ -193,17 +189,17 @@ class AbstractDemoPlayer(MediaPlayerEntity):
|
|||||||
|
|
||||||
def media_play(self) -> None:
|
def media_play(self) -> None:
|
||||||
"""Send play command."""
|
"""Send play command."""
|
||||||
self._player_state = STATE_PLAYING
|
self._player_state = MediaPlayerState.PLAYING
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def media_pause(self) -> None:
|
def media_pause(self) -> None:
|
||||||
"""Send pause command."""
|
"""Send pause command."""
|
||||||
self._player_state = STATE_PAUSED
|
self._player_state = MediaPlayerState.PAUSED
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def media_stop(self) -> None:
|
def media_stop(self) -> None:
|
||||||
"""Send stop command."""
|
"""Send stop command."""
|
||||||
self._player_state = STATE_OFF
|
self._player_state = MediaPlayerState.OFF
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def set_shuffle(self, shuffle: bool) -> None:
|
def set_shuffle(self, shuffle: bool) -> None:
|
||||||
@ -222,6 +218,8 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
|||||||
|
|
||||||
# We only implement the methods that we support
|
# We only implement the methods that we support
|
||||||
|
|
||||||
|
_attr_media_content_type = MediaType.MOVIE
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, name: str, youtube_id: str, media_title: str, duration: int
|
self, name: str, youtube_id: str, media_title: str, duration: int
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -238,11 +236,6 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
|||||||
"""Return the content ID of current playing media."""
|
"""Return the content ID of current playing media."""
|
||||||
return self.youtube_id
|
return self.youtube_id
|
||||||
|
|
||||||
@property
|
|
||||||
def media_content_type(self) -> str:
|
|
||||||
"""Return the content type of current playing media."""
|
|
||||||
return MEDIA_TYPE_MOVIE
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_duration(self) -> int:
|
def media_duration(self) -> int:
|
||||||
"""Return the duration of current playing media in seconds."""
|
"""Return the duration of current playing media in seconds."""
|
||||||
@ -276,7 +269,7 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
|||||||
|
|
||||||
position = self._progress
|
position = self._progress
|
||||||
|
|
||||||
if self._player_state == STATE_PLAYING:
|
if self._player_state == MediaPlayerState.PLAYING:
|
||||||
position += int(
|
position += int(
|
||||||
(dt_util.utcnow() - self._progress_updated_at).total_seconds()
|
(dt_util.utcnow() - self._progress_updated_at).total_seconds()
|
||||||
)
|
)
|
||||||
@ -289,7 +282,7 @@ class DemoYoutubePlayer(AbstractDemoPlayer):
|
|||||||
|
|
||||||
Returns value from homeassistant.util.dt.utcnow().
|
Returns value from homeassistant.util.dt.utcnow().
|
||||||
"""
|
"""
|
||||||
if self._player_state == STATE_PLAYING:
|
if self._player_state == MediaPlayerState.PLAYING:
|
||||||
return self._progress_updated_at
|
return self._progress_updated_at
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -310,6 +303,8 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
|||||||
|
|
||||||
# We only implement the methods that we support
|
# We only implement the methods that we support
|
||||||
|
|
||||||
|
_attr_media_content_type = MediaType.MUSIC
|
||||||
|
|
||||||
tracks = [
|
tracks = [
|
||||||
("Technohead", "I Wanna Be A Hippy (Flamman & Abraxas Radio Mix)"),
|
("Technohead", "I Wanna Be A Hippy (Flamman & Abraxas Radio Mix)"),
|
||||||
("Paul Elstak", "Luv U More"),
|
("Paul Elstak", "Luv U More"),
|
||||||
@ -338,7 +333,7 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
|||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
self._cur_track = 0
|
self._cur_track = 0
|
||||||
self._group_members: list[str] = []
|
self._group_members: list[str] = []
|
||||||
self._repeat = REPEAT_MODE_OFF
|
self._repeat = RepeatMode.OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def group_members(self) -> list[str]:
|
def group_members(self) -> list[str]:
|
||||||
@ -350,11 +345,6 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
|||||||
"""Return the content ID of current playing media."""
|
"""Return the content ID of current playing media."""
|
||||||
return "bounzz-1"
|
return "bounzz-1"
|
||||||
|
|
||||||
@property
|
|
||||||
def media_content_type(self) -> str:
|
|
||||||
"""Return the content type of current playing media."""
|
|
||||||
return MEDIA_TYPE_MUSIC
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_duration(self) -> int:
|
def media_duration(self) -> int:
|
||||||
"""Return the duration of current playing media in seconds."""
|
"""Return the duration of current playing media in seconds."""
|
||||||
@ -386,7 +376,7 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
|||||||
return self._cur_track + 1
|
return self._cur_track + 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repeat(self) -> str:
|
def repeat(self) -> RepeatMode:
|
||||||
"""Return current repeat mode."""
|
"""Return current repeat mode."""
|
||||||
return self._repeat
|
return self._repeat
|
||||||
|
|
||||||
@ -411,10 +401,10 @@ class DemoMusicPlayer(AbstractDemoPlayer):
|
|||||||
"""Clear players playlist."""
|
"""Clear players playlist."""
|
||||||
self.tracks = []
|
self.tracks = []
|
||||||
self._cur_track = 0
|
self._cur_track = 0
|
||||||
self._player_state = STATE_OFF
|
self._player_state = MediaPlayerState.OFF
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def set_repeat(self, repeat: str) -> None:
|
def set_repeat(self, repeat: RepeatMode) -> None:
|
||||||
"""Enable/disable repeat mode."""
|
"""Enable/disable repeat mode."""
|
||||||
self._repeat = repeat
|
self._repeat = repeat
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
@ -438,6 +428,7 @@ class DemoTVShowPlayer(AbstractDemoPlayer):
|
|||||||
# We only implement the methods that we support
|
# We only implement the methods that we support
|
||||||
|
|
||||||
_attr_device_class = MediaPlayerDeviceClass.TV
|
_attr_device_class = MediaPlayerDeviceClass.TV
|
||||||
|
_attr_media_content_type = MediaType.TVSHOW
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize the demo device."""
|
"""Initialize the demo device."""
|
||||||
@ -452,11 +443,6 @@ class DemoTVShowPlayer(AbstractDemoPlayer):
|
|||||||
"""Return the content ID of current playing media."""
|
"""Return the content ID of current playing media."""
|
||||||
return "house-of-cards-1"
|
return "house-of-cards-1"
|
||||||
|
|
||||||
@property
|
|
||||||
def media_content_type(self) -> str:
|
|
||||||
"""Return the content type of current playing media."""
|
|
||||||
return MEDIA_TYPE_TVSHOW
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_duration(self) -> int:
|
def media_duration(self) -> int:
|
||||||
"""Return the duration of current playing media in seconds."""
|
"""Return the duration of current playing media in seconds."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user