11"""Media player platform for Alexa Devices."""
22
3- from dataclasses import dataclass
43from datetime import datetime
5- from typing import Any , Final
4+ from typing import Any
65
76from aioamazondevices .structures import (
87 AmazonMediaControls ,
3837)
3938
4039
41- @dataclass (frozen = True , kw_only = True )
42- class AmazonDevicesMediaPlayerEntityDescription (MediaPlayerEntityDescription ):
43- """Describes an Alexa Devices media player entity."""
44-
45-
46- MEDIA_PLAYERS : Final = (
47- AmazonDevicesMediaPlayerEntityDescription (
48- key = "media" ,
49- ),
50- )
51-
52-
5340async def async_setup_entry (
5441 hass : HomeAssistant ,
5542 entry : AmazonConfigEntry ,
@@ -69,9 +56,10 @@ def _check_device() -> None:
6956 continue
7057
7158 known_devices .add (serial_num )
72- new_entities .extend (
73- AlexaDevicesMediaPlayer (coordinator , serial_num , description )
74- for description in MEDIA_PLAYERS
59+ new_entities .append (
60+ AlexaDevicesMediaPlayer (
61+ coordinator , serial_num , MediaPlayerEntityDescription (key = "media" )
62+ )
7563 )
7664
7765 if new_entities :
@@ -85,8 +73,6 @@ def _check_device() -> None:
8573class AlexaDevicesMediaPlayer (AmazonEntity , MediaPlayerEntity ):
8674 """Representation of an Alexa device media player."""
8775
88- entity_description : AmazonDevicesMediaPlayerEntityDescription
89-
9076 _attr_name = None # Uses the device name
9177 _attr_device_class = MediaPlayerDeviceClass .SPEAKER
9278 _attr_volume_step = 0.05
@@ -95,7 +81,7 @@ def __init__(
9581 self ,
9682 coordinator : AmazonDevicesCoordinator ,
9783 serial_num : str ,
98- description : AmazonDevicesMediaPlayerEntityDescription ,
84+ description : MediaPlayerEntityDescription ,
9985 ) -> None :
10086 """Initialize."""
10187 self ._prev_volume : int | None = None
@@ -214,7 +200,7 @@ def media_position_updated_at(self) -> datetime | None:
214200 @property
215201 def media_content_type (self ) -> MediaType | None :
216202 """Content type — tells HA what kind of media is playing."""
217- if self .state in [ MediaPlayerState .PLAYING , MediaPlayerState .PAUSED ] :
203+ if self .state in ( MediaPlayerState .PLAYING , MediaPlayerState .PAUSED ) :
218204 return MediaType .MUSIC
219205 return None
220206
@@ -227,7 +213,8 @@ async def async_play_media(
227213 ** kwargs : Any ,
228214 ) -> None :
229215 """Play a piece of media."""
230- await self .async_call_alexa_music (media_id , media_type )
216+ provider = media_type .value if isinstance (media_type , MediaType ) else media_type
217+ await self .async_call_alexa_music (media_id , provider )
231218
232219 @alexa_api_call
233220 async def async_call_alexa_music (
0 commit comments