Skip to content

fix: fix media player supported features for HA beta #2150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 30 additions & 46 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,11 @@
ATTR_MEDIA_ANNOUNCE,
async_process_play_media_url,
)
from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SELECT_SOURCE,
SUPPORT_SHUFFLE_SET,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
)

from homeassistant.const import (
CONF_EMAIL,
CONF_NAME,
CONF_PASSWORD,
STATE_IDLE,
STATE_PAUSED,
STATE_PLAYING,
STATE_STANDBY,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -75,24 +57,26 @@
try:
from homeassistant.components.media_player import (
MediaPlayerEntity as MediaPlayerDevice,
MediaPlayerEntityFeature,
MediaPlayerState,
MediaType,
)
except ImportError:
from homeassistant.components.media_player import MediaPlayerDevice

SUPPORT_ALEXA = (
SUPPORT_PAUSE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_STOP
| SUPPORT_VOLUME_SET
| SUPPORT_PLAY
| SUPPORT_PLAY_MEDIA
| SUPPORT_TURN_OFF
| SUPPORT_TURN_ON
| SUPPORT_VOLUME_MUTE
| SUPPORT_PAUSE
| SUPPORT_SELECT_SOURCE
| SUPPORT_SHUFFLE_SET
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.VOLUME_SET
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.PLAY_MEDIA
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.SHUFFLE_SET
)
_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -493,7 +477,7 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
self.async_write_ha_state()
await _refresh_if_no_audiopush(already_refreshed)
elif "push_activity" in event:
if self.state in {STATE_IDLE, STATE_PAUSED, STATE_PLAYING}:
if self.state in {MediaPlayerState.IDLE, MediaPlayerState.PAUSED, MediaPlayerState.PLAYING}:
_LOGGER.debug(
"%s: %s checking for potential state update due to push activity on %s",
hide_email(self._login.email),
Expand Down Expand Up @@ -620,7 +604,7 @@ async def refresh(self, device=None, skip_api: bool = False):
and self.hass.data[DATA_ALEXAMEDIA]["accounts"][
self._login.email
]["entities"]["media_player"][x].state
== STATE_PLAYING
== MediaPlayerState.PLAYING
),
self._parent_clusters,
)
Expand Down Expand Up @@ -898,12 +882,12 @@ def state(self):
if not self.available:
return STATE_UNAVAILABLE
if self._media_player_state == "PLAYING":
return STATE_PLAYING
return MediaPlayerState.PLAYING
if self._media_player_state == "PAUSED":
return STATE_PAUSED
return MediaPlayerState.PAUSED
if self._media_player_state == "IDLE":
return STATE_IDLE
return STATE_STANDBY
return MediaPlayerState.IDLE
return MediaPlayerState.STANDBY

def update(self):
"""Get the latest details on a media player synchronously."""
Expand Down Expand Up @@ -952,7 +936,7 @@ async def async_update(self):
self.hass.data[DATA_ALEXAMEDIA]["accounts"].get(email, {}).get("http2")
)
if (
self.state in [STATE_PLAYING]
self.state in [MediaPlayerState.PLAYING]
and
# only enable polling if websocket not connected
(
Expand Down Expand Up @@ -1009,9 +993,9 @@ async def async_update(self):
@property
def media_content_type(self):
"""Return the content type of current playing media."""
if self.state in [STATE_PLAYING, STATE_PAUSED]:
return MEDIA_TYPE_MUSIC
return STATE_STANDBY
if self.state in [MediaPlayerState.PLAYING, MediaPlayerState.PAUSED]:
return MediaType.MUSIC
return MediaPlayerState.STANDBY

@property
def media_artist(self):
Expand Down Expand Up @@ -1173,7 +1157,7 @@ async def async_mute_volume(self, mute):
@_catch_login_errors
async def async_media_play(self):
"""Send play command."""
if not (self.state in [STATE_PLAYING, STATE_PAUSED] and self.available):
if not (self.state in [MediaPlayerState.PLAYING, MediaPlayerState.PAUSED] and self.available):
return
if self._playing_parent:
await self._playing_parent.async_media_play()
Expand All @@ -1190,7 +1174,7 @@ async def async_media_play(self):
@_catch_login_errors
async def async_media_pause(self):
"""Send pause command."""
if not (self.state in [STATE_PLAYING, STATE_PAUSED] and self.available):
if not (self.state in [MediaPlayerState.PLAYING, MediaPlayerState.PAUSED] and self.available):
return
if self._playing_parent:
await self._playing_parent.async_media_pause()
Expand Down Expand Up @@ -1257,7 +1241,7 @@ async def async_turn_on(self):
@_catch_login_errors
async def async_media_next_track(self):
"""Send next track command."""
if not (self.state in [STATE_PLAYING, STATE_PAUSED] and self.available):
if not (self.state in [MediaPlayerState.PLAYING, MediaPlayerState.PAUSED] and self.available):
return
if self._playing_parent:
await self._playing_parent.async_media_next_track()
Expand All @@ -1274,7 +1258,7 @@ async def async_media_next_track(self):
@_catch_login_errors
async def async_media_previous_track(self):
"""Send previous track command."""
if not (self.state in [STATE_PLAYING, STATE_PAUSED] and self.available):
if not (self.state in [MediaPlayerState.PLAYING, MediaPlayerState.PAUSED] and self.available):
return
if self._playing_parent:
await self._playing_parent.async_media_previous_track()
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"content_in_root": false,
"zip_release": true,
"filename": "alexa_media.zip",
"homeassistant": "2022.11.0b0"
"homeassistant": "2024.1.0b0"
}