Use new media player enums [s] (#78064)
parent
45d0ec7150
commit
6b157921ea
|
@ -26,20 +26,11 @@ from homeassistant.components.media_player import (
|
|||
MediaPlayerDeviceClass,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
)
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_APP,
|
||||
MEDIA_TYPE_CHANNEL,
|
||||
MediaPlayerState,
|
||||
MediaType,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
CONF_MODEL,
|
||||
CONF_NAME,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_MODEL, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_component
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
@ -199,15 +190,17 @@ class SamsungTVDevice(MediaPlayerEntity):
|
|||
return
|
||||
old_state = self._attr_state
|
||||
if self._power_off_in_progress():
|
||||
self._attr_state = STATE_OFF
|
||||
self._attr_state = MediaPlayerState.OFF
|
||||
else:
|
||||
self._attr_state = (
|
||||
STATE_ON if await self._bridge.async_is_on() else STATE_OFF
|
||||
MediaPlayerState.ON
|
||||
if await self._bridge.async_is_on()
|
||||
else MediaPlayerState.OFF
|
||||
)
|
||||
if self._attr_state != old_state:
|
||||
LOGGER.debug("TV %s state updated to %s", self._host, self._attr_state)
|
||||
|
||||
if self._attr_state != STATE_ON:
|
||||
if self._attr_state != MediaPlayerState.ON:
|
||||
if self._dmr_device and self._dmr_device.is_subscribed:
|
||||
await self._dmr_device.async_unsubscribe_services()
|
||||
return
|
||||
|
@ -364,7 +357,7 @@ class SamsungTVDevice(MediaPlayerEntity):
|
|||
if self._auth_failed:
|
||||
return False
|
||||
return (
|
||||
self._attr_state == STATE_ON
|
||||
self._attr_state == MediaPlayerState.ON
|
||||
or self._on_script is not None
|
||||
or self._mac is not None
|
||||
or self._power_off_in_progress()
|
||||
|
@ -426,11 +419,11 @@ class SamsungTVDevice(MediaPlayerEntity):
|
|||
self, media_type: str, media_id: str, **kwargs: Any
|
||||
) -> None:
|
||||
"""Support changing a channel."""
|
||||
if media_type == MEDIA_TYPE_APP:
|
||||
if media_type == MediaType.APP:
|
||||
await self._async_launch_app(media_id)
|
||||
return
|
||||
|
||||
if media_type != MEDIA_TYPE_CHANNEL:
|
||||
if media_type != MediaType.CHANNEL:
|
||||
LOGGER.error("Unsupported media type")
|
||||
return
|
||||
|
||||
|
|
|
@ -7,14 +7,9 @@ from sisyphus_control import Track
|
|||
from homeassistant.components.media_player import (
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
MediaPlayerState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
STATE_IDLE,
|
||||
STATE_OFF,
|
||||
STATE_PAUSED,
|
||||
STATE_PLAYING,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -89,17 +84,17 @@ class SisyphusPlayer(MediaPlayerEntity):
|
|||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> MediaPlayerState | None:
|
||||
"""Return the current state of the table; sleeping maps to off."""
|
||||
if self._table.state in ["homing", "playing"]:
|
||||
return STATE_PLAYING
|
||||
return MediaPlayerState.PLAYING
|
||||
if self._table.state == "paused":
|
||||
if self._table.is_sleeping:
|
||||
return STATE_OFF
|
||||
return MediaPlayerState.OFF
|
||||
|
||||
return STATE_PAUSED
|
||||
return MediaPlayerState.PAUSED
|
||||
if self._table.state == "waiting":
|
||||
return STATE_IDLE
|
||||
return MediaPlayerState.IDLE
|
||||
|
||||
return None
|
||||
|
||||
|
|
|
@ -14,12 +14,10 @@ from homeassistant.components.media_player import (
|
|||
MediaPlayerDeviceClass,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
)
|
||||
from homeassistant.components.media_player.browse_media import (
|
||||
MediaPlayerState,
|
||||
async_process_play_media_url,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -28,9 +26,9 @@ from homeassistant.util.dt import utcnow
|
|||
from .const import DEFAULT_NAME, DOMAIN, PLAYER_EVENT
|
||||
|
||||
STATE_MAPPING = {
|
||||
PlayerState.IDLE: STATE_IDLE,
|
||||
PlayerState.PLAYING: STATE_PLAYING,
|
||||
PlayerState.PAUSED: STATE_PAUSED,
|
||||
PlayerState.IDLE: MediaPlayerState.IDLE,
|
||||
PlayerState.PLAYING: MediaPlayerState.PLAYING,
|
||||
PlayerState.PAUSED: MediaPlayerState.PAUSED,
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,10 +130,10 @@ class SlimProtoPlayer(MediaPlayerEntity):
|
|||
return self.player.connected
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def state(self) -> MediaPlayerState:
|
||||
"""Return current state."""
|
||||
if not self.player.powered:
|
||||
return STATE_OFF
|
||||
return MediaPlayerState.OFF
|
||||
return STATE_MAPPING[self.player.state]
|
||||
|
||||
@callback
|
||||
|
|
|
@ -19,9 +19,10 @@ import voluptuous as vol
|
|||
from homeassistant.components.media_player import (
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
MediaPlayerState,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers import (
|
||||
|
@ -296,11 +297,11 @@ class SongpalEntity(MediaPlayerEntity):
|
|||
return [src.title for src in self._sources.values()]
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> MediaPlayerState:
|
||||
"""Return current state."""
|
||||
if self._state:
|
||||
return STATE_ON
|
||||
return STATE_OFF
|
||||
return MediaPlayerState.ON
|
||||
return MediaPlayerState.OFF
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
|
|
|
@ -18,28 +18,21 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components import media_source, spotify
|
||||
from homeassistant.components.media_player import (
|
||||
ATTR_INPUT_SOURCE,
|
||||
ATTR_MEDIA_ENQUEUE,
|
||||
BrowseMedia,
|
||||
MediaPlayerEnqueue,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
MediaPlayerState,
|
||||
MediaType,
|
||||
RepeatMode,
|
||||
async_process_play_media_url,
|
||||
)
|
||||
from homeassistant.components.media_player.browse_media import BrowseMedia
|
||||
from homeassistant.components.media_player.const import (
|
||||
ATTR_INPUT_SOURCE,
|
||||
ATTR_MEDIA_ENQUEUE,
|
||||
MEDIA_TYPE_ALBUM,
|
||||
MEDIA_TYPE_ARTIST,
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MEDIA_TYPE_PLAYLIST,
|
||||
MEDIA_TYPE_TRACK,
|
||||
REPEAT_MODE_ALL,
|
||||
REPEAT_MODE_OFF,
|
||||
REPEAT_MODE_ONE,
|
||||
)
|
||||
from homeassistant.components.plex.const import PLEX_URI_SCHEME
|
||||
from homeassistant.components.plex.services import process_plex_payload
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TIME, STATE_IDLE, STATE_PAUSED, STATE_PLAYING
|
||||
from homeassistant.const import ATTR_TIME
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform, service
|
||||
|
@ -74,9 +67,9 @@ UNJOIN_SERVICE_TIMEOUT = 0.1
|
|||
VOLUME_INCREMENT = 2
|
||||
|
||||
REPEAT_TO_SONOS = {
|
||||
REPEAT_MODE_OFF: False,
|
||||
REPEAT_MODE_ALL: True,
|
||||
REPEAT_MODE_ONE: "ONE",
|
||||
RepeatMode.OFF: False,
|
||||
RepeatMode.ALL: True,
|
||||
RepeatMode.ONE: "ONE",
|
||||
}
|
||||
|
||||
SONOS_TO_REPEAT = {meaning: mode for mode, meaning in REPEAT_TO_SONOS.items()}
|
||||
|
@ -211,7 +204,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
)
|
||||
_attr_media_content_type = MEDIA_TYPE_MUSIC
|
||||
_attr_media_content_type = MediaType.MUSIC
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker) -> None:
|
||||
"""Initialize the media player entity."""
|
||||
|
@ -259,7 +252,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
return hash(self.unique_id)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def state(self) -> MediaPlayerState:
|
||||
"""Return the state of the entity."""
|
||||
if self.media.playback_status in (
|
||||
"PAUSED_PLAYBACK",
|
||||
|
@ -268,14 +261,14 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
# Sonos can consider itself "paused" but without having media loaded
|
||||
# (happens if playing Spotify and via Spotify app you pick another device to play on)
|
||||
if self.media.title is None:
|
||||
return STATE_IDLE
|
||||
return STATE_PAUSED
|
||||
return MediaPlayerState.IDLE
|
||||
return MediaPlayerState.PAUSED
|
||||
if self.media.playback_status in (
|
||||
SONOS_STATE_PLAYING,
|
||||
SONOS_STATE_TRANSITIONING,
|
||||
):
|
||||
return STATE_PLAYING
|
||||
return STATE_IDLE
|
||||
return MediaPlayerState.PLAYING
|
||||
return MediaPlayerState.IDLE
|
||||
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Retrieve latest state by polling."""
|
||||
|
@ -397,7 +390,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
]
|
||||
|
||||
@soco_error(UPNP_ERRORS_TO_IGNORE)
|
||||
def set_repeat(self, repeat: str) -> None:
|
||||
def set_repeat(self, repeat: RepeatMode) -> None:
|
||||
"""Set repeat mode."""
|
||||
sonos_shuffle = PLAY_MODES[self.media.play_mode][0]
|
||||
sonos_repeat = REPEAT_TO_SONOS[repeat]
|
||||
|
@ -521,7 +514,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
|
||||
if media_source.is_media_source_id(media_id):
|
||||
is_radio = media_id.startswith("media-source://radio_browser/")
|
||||
media_type = MEDIA_TYPE_MUSIC
|
||||
media_type = MediaType.MUSIC
|
||||
media_id = (
|
||||
run_coroutine_threadsafe(
|
||||
media_source.async_resolve_media(
|
||||
|
@ -588,7 +581,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
media_id, timeout=LONG_SERVICE_TIMEOUT
|
||||
)
|
||||
soco.play_from_queue(0)
|
||||
elif media_type in (MEDIA_TYPE_MUSIC, MEDIA_TYPE_TRACK):
|
||||
elif media_type in {MediaType.MUSIC, MediaType.TRACK}:
|
||||
# If media ID is a relative URL, we serve it from HA.
|
||||
media_id = async_process_play_media_url(self.hass, media_id)
|
||||
|
||||
|
@ -604,7 +597,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
soco.play_from_queue(new_pos - 1)
|
||||
elif enqueue == MediaPlayerEnqueue.REPLACE:
|
||||
soco.play_uri(media_id, force_radio=is_radio)
|
||||
elif media_type == MEDIA_TYPE_PLAYLIST:
|
||||
elif media_type == MediaType.PLAYLIST:
|
||||
if media_id.startswith("S:"):
|
||||
item = media_browser.get_media(self.media.library, media_id, media_type)
|
||||
soco.play_uri(item.get_uri())
|
||||
|
@ -700,7 +693,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
) -> tuple[bytes | None, str | None]:
|
||||
"""Fetch media browser image to serve via proxy."""
|
||||
if (
|
||||
media_content_type in [MEDIA_TYPE_ALBUM, MEDIA_TYPE_ARTIST]
|
||||
media_content_type in {MediaType.ALBUM, MediaType.ARTIST}
|
||||
and media_content_id
|
||||
):
|
||||
item = await self.hass.async_add_executor_job(
|
||||
|
|
|
@ -15,18 +15,12 @@ from homeassistant.components.media_player import (
|
|||
BrowseMedia,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
)
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_EPISODE,
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MEDIA_TYPE_PLAYLIST,
|
||||
MEDIA_TYPE_TRACK,
|
||||
REPEAT_MODE_ALL,
|
||||
REPEAT_MODE_OFF,
|
||||
REPEAT_MODE_ONE,
|
||||
MediaPlayerState,
|
||||
MediaType,
|
||||
RepeatMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ID, STATE_IDLE, STATE_PAUSED, STATE_PLAYING
|
||||
from homeassistant.const import CONF_ID
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
|
@ -58,9 +52,9 @@ SUPPORT_SPOTIFY = (
|
|||
)
|
||||
|
||||
REPEAT_MODE_MAPPING_TO_HA = {
|
||||
"context": REPEAT_MODE_ALL,
|
||||
"off": REPEAT_MODE_OFF,
|
||||
"track": REPEAT_MODE_ONE,
|
||||
"context": RepeatMode.ALL,
|
||||
"off": RepeatMode.OFF,
|
||||
"track": RepeatMode.ONE,
|
||||
}
|
||||
|
||||
REPEAT_MODE_MAPPING_TO_SPOTIFY = {
|
||||
|
@ -110,7 +104,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
|
||||
_attr_has_entity_name = True
|
||||
_attr_icon = "mdi:spotify"
|
||||
_attr_media_content_type = MEDIA_TYPE_MUSIC
|
||||
_attr_media_content_type = MediaType.MUSIC
|
||||
_attr_media_image_remotely_accessible = False
|
||||
|
||||
def __init__(
|
||||
|
@ -144,13 +138,13 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
self._playlist: dict | None = None
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def state(self) -> MediaPlayerState:
|
||||
"""Return the playback state."""
|
||||
if not self._currently_playing:
|
||||
return STATE_IDLE
|
||||
return MediaPlayerState.IDLE
|
||||
if self._currently_playing["is_playing"]:
|
||||
return STATE_PLAYING
|
||||
return STATE_PAUSED
|
||||
return MediaPlayerState.PLAYING
|
||||
return MediaPlayerState.PAUSED
|
||||
|
||||
@property
|
||||
def volume_level(self) -> float | None:
|
||||
|
@ -315,7 +309,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
# Yet, they do generate those types of URI in their official clients.
|
||||
media_id = str(URL(media_id).with_query(None).with_fragment(None))
|
||||
|
||||
if media_type in (MEDIA_TYPE_TRACK, MEDIA_TYPE_EPISODE, MEDIA_TYPE_MUSIC):
|
||||
if media_type in {MediaType.TRACK, MediaType.EPISODE, MediaType.MUSIC}:
|
||||
kwargs["uris"] = [media_id]
|
||||
elif media_type in PLAYABLE_MEDIA_TYPES:
|
||||
kwargs["context_uri"] = media_id
|
||||
|
@ -338,7 +332,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
for device in self.data.devices.data:
|
||||
if device["name"] == source:
|
||||
self.data.client.transfer_playback(
|
||||
device["id"], self.state == STATE_PLAYING
|
||||
device["id"], self.state == MediaPlayerState.PLAYING
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -348,7 +342,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
self.data.client.shuffle(shuffle)
|
||||
|
||||
@spotify_exception_handler
|
||||
def set_repeat(self, repeat: str) -> None:
|
||||
def set_repeat(self, repeat: RepeatMode) -> None:
|
||||
"""Set repeat mode."""
|
||||
if repeat not in REPEAT_MODE_MAPPING_TO_SPOTIFY:
|
||||
raise ValueError(f"Unsupported repeat mode: {repeat}")
|
||||
|
@ -374,7 +368,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||
self._playlist is None or self._playlist["uri"] != context["uri"]
|
||||
):
|
||||
self._playlist = None
|
||||
if context["type"] == MEDIA_TYPE_PLAYLIST:
|
||||
if context["type"] == MediaType.PLAYLIST:
|
||||
self._playlist = self.data.client.playlist(current["context"]["uri"])
|
||||
|
||||
async def async_browse_media(
|
||||
|
|
|
@ -11,21 +11,15 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components import media_source
|
||||
from homeassistant.components.media_player import (
|
||||
ATTR_MEDIA_ENQUEUE,
|
||||
MediaPlayerEnqueue,
|
||||
MediaPlayerEntity,
|
||||
MediaPlayerEntityFeature,
|
||||
)
|
||||
from homeassistant.components.media_player.browse_media import (
|
||||
MediaPlayerState,
|
||||
MediaType,
|
||||
RepeatMode,
|
||||
async_process_play_media_url,
|
||||
)
|
||||
from homeassistant.components.media_player.const import (
|
||||
ATTR_MEDIA_ENQUEUE,
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MEDIA_TYPE_PLAYLIST,
|
||||
REPEAT_MODE_ALL,
|
||||
REPEAT_MODE_OFF,
|
||||
REPEAT_MODE_ONE,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_COMMAND,
|
||||
|
@ -34,10 +28,6 @@ from homeassistant.const import (
|
|||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
STATE_IDLE,
|
||||
STATE_OFF,
|
||||
STATE_PAUSED,
|
||||
STATE_PLAYING,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import (
|
||||
|
@ -94,9 +84,9 @@ ATTR_TO_PROPERTY = [
|
|||
]
|
||||
|
||||
SQUEEZEBOX_MODE = {
|
||||
"pause": STATE_PAUSED,
|
||||
"play": STATE_PLAYING,
|
||||
"stop": STATE_IDLE,
|
||||
"pause": MediaPlayerState.PAUSED,
|
||||
"play": MediaPlayerState.PLAYING,
|
||||
"stop": MediaPlayerState.IDLE,
|
||||
}
|
||||
|
||||
|
||||
|
@ -289,10 +279,10 @@ class SqueezeBoxEntity(MediaPlayerEntity):
|
|||
self._remove_dispatcher()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> MediaPlayerState | None:
|
||||
"""Return the state of the device."""
|
||||
if not self._player.power:
|
||||
return STATE_OFF
|
||||
return MediaPlayerState.OFF
|
||||
if self._player.mode:
|
||||
return SQUEEZEBOX_MODE.get(self._player.mode)
|
||||
return None
|
||||
|
@ -345,8 +335,8 @@ class SqueezeBoxEntity(MediaPlayerEntity):
|
|||
if not self._player.playlist:
|
||||
return None
|
||||
if len(self._player.playlist) > 1:
|
||||
return MEDIA_TYPE_PLAYLIST
|
||||
return MEDIA_TYPE_MUSIC
|
||||
return MediaType.PLAYLIST
|
||||
return MediaType.MUSIC
|
||||
|
||||
@property
|
||||
def media_duration(self):
|
||||
|
@ -387,10 +377,10 @@ class SqueezeBoxEntity(MediaPlayerEntity):
|
|||
def repeat(self):
|
||||
"""Repeat setting."""
|
||||
if self._player.repeat == "song":
|
||||
return REPEAT_MODE_ONE
|
||||
return RepeatMode.ONE
|
||||
if self._player.repeat == "playlist":
|
||||
return REPEAT_MODE_ALL
|
||||
return REPEAT_MODE_OFF
|
||||
return RepeatMode.ALL
|
||||
return RepeatMode.OFF
|
||||
|
||||
@property
|
||||
def shuffle(self):
|
||||
|
@ -491,13 +481,13 @@ class SqueezeBoxEntity(MediaPlayerEntity):
|
|||
cmd = "play"
|
||||
|
||||
if media_source.is_media_source_id(media_id):
|
||||
media_type = MEDIA_TYPE_MUSIC
|
||||
media_type = MediaType.MUSIC
|
||||
play_item = await media_source.async_resolve_media(
|
||||
self.hass, media_id, self.entity_id
|
||||
)
|
||||
media_id = play_item.url
|
||||
|
||||
if media_type in MEDIA_TYPE_MUSIC:
|
||||
if media_type in MediaType.MUSIC:
|
||||
if not media_id.startswith(SQUEEZEBOX_SOURCE_STRINGS):
|
||||
# do not process special squeezebox "source" media ids
|
||||
media_id = async_process_play_media_url(self.hass, media_id)
|
||||
|
@ -505,12 +495,12 @@ class SqueezeBoxEntity(MediaPlayerEntity):
|
|||
await self._player.async_load_url(media_id, cmd)
|
||||
return
|
||||
|
||||
if media_type == MEDIA_TYPE_PLAYLIST:
|
||||
if media_type == MediaType.PLAYLIST:
|
||||
try:
|
||||
# a saved playlist by number
|
||||
payload = {
|
||||
"search_id": int(media_id),
|
||||
"search_type": MEDIA_TYPE_PLAYLIST,
|
||||
"search_type": MediaType.PLAYLIST,
|
||||
}
|
||||
playlist = await generate_playlist(self._player, payload)
|
||||
except ValueError:
|
||||
|
@ -531,11 +521,11 @@ class SqueezeBoxEntity(MediaPlayerEntity):
|
|||
if index is not None:
|
||||
await self._player.async_index(index)
|
||||
|
||||
async def async_set_repeat(self, repeat: str) -> None:
|
||||
async def async_set_repeat(self, repeat: RepeatMode) -> None:
|
||||
"""Set the repeat mode."""
|
||||
if repeat == REPEAT_MODE_ALL:
|
||||
if repeat == RepeatMode.ALL:
|
||||
repeat_mode = "playlist"
|
||||
elif repeat == REPEAT_MODE_ONE:
|
||||
elif repeat == RepeatMode.ONE:
|
||||
repeat_mode = "song"
|
||||
else:
|
||||
repeat_mode = "none"
|
||||
|
|
Loading…
Reference in New Issue