mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use attributes in ue smart radio media player (#82840)
This commit is contained in:
parent
4bf1475c95
commit
6a17937dc3
@ -82,6 +82,7 @@ def setup_platform(
|
|||||||
class UERadioDevice(MediaPlayerEntity):
|
class UERadioDevice(MediaPlayerEntity):
|
||||||
"""Representation of a Logitech UE Smart Radio device."""
|
"""Representation of a Logitech UE Smart Radio device."""
|
||||||
|
|
||||||
|
_attr_icon = ICON
|
||||||
_attr_media_content_type = MediaType.MUSIC
|
_attr_media_content_type = MediaType.MUSIC
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
MediaPlayerEntityFeature.PLAY
|
MediaPlayerEntityFeature.PLAY
|
||||||
@ -99,13 +100,9 @@ class UERadioDevice(MediaPlayerEntity):
|
|||||||
"""Initialize the Logitech UE Smart Radio device."""
|
"""Initialize the Logitech UE Smart Radio device."""
|
||||||
self._session = session
|
self._session = session
|
||||||
self._player_id = player_id
|
self._player_id = player_id
|
||||||
self._name = player_name
|
self._attr_name = player_name
|
||||||
self._state = None
|
self._attr_volume_level = 0
|
||||||
self._volume = 0
|
|
||||||
self._last_volume = 0
|
self._last_volume = 0
|
||||||
self._media_title = None
|
|
||||||
self._media_artist = None
|
|
||||||
self._media_artwork_url = None
|
|
||||||
|
|
||||||
def send_command(self, command):
|
def send_command(self, command):
|
||||||
"""Send command to radio."""
|
"""Send command to radio."""
|
||||||
@ -128,63 +125,28 @@ class UERadioDevice(MediaPlayerEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if request["error"] is not None:
|
if request["error"] is not None:
|
||||||
self._state = None
|
self._attr_state = None
|
||||||
return
|
return
|
||||||
|
|
||||||
if request["result"]["power"] == 0:
|
if request["result"]["power"] == 0:
|
||||||
self._state = MediaPlayerState.OFF
|
self._attr_state = MediaPlayerState.OFF
|
||||||
else:
|
else:
|
||||||
self._state = PLAYBACK_DICT[request["result"]["mode"]]
|
self._attr_state = PLAYBACK_DICT[request["result"]["mode"]]
|
||||||
|
|
||||||
media_info = request["result"]["playlist_loop"][0]
|
media_info = request["result"]["playlist_loop"][0]
|
||||||
|
|
||||||
self._volume = request["result"]["mixer volume"] / 100
|
self._attr_volume_level = request["result"]["mixer volume"] / 100
|
||||||
self._media_artwork_url = media_info["artwork_url"]
|
self._attr_media_image_url = media_info["artwork_url"]
|
||||||
self._media_title = media_info["title"]
|
self._attr_media_title = media_info["title"]
|
||||||
if "artist" in media_info:
|
if "artist" in media_info:
|
||||||
self._media_artist = media_info["artist"]
|
self._attr_media_artist = media_info["artist"]
|
||||||
else:
|
else:
|
||||||
self._media_artist = media_info.get("remote_title")
|
self._attr_media_artist = media_info.get("remote_title")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def is_volume_muted(self) -> bool:
|
||||||
"""Return the name of the device."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the device."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon to use in the frontend, if any."""
|
|
||||||
return ICON
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_volume_muted(self):
|
|
||||||
"""Boolean if volume is currently muted."""
|
"""Boolean if volume is currently muted."""
|
||||||
return self._volume <= 0
|
return self.volume_level is not None and self.volume_level <= 0
|
||||||
|
|
||||||
@property
|
|
||||||
def volume_level(self):
|
|
||||||
"""Volume level of the media player (0..1)."""
|
|
||||||
return self._volume
|
|
||||||
|
|
||||||
@property
|
|
||||||
def media_image_url(self):
|
|
||||||
"""Image URL of current playing media."""
|
|
||||||
return self._media_artwork_url
|
|
||||||
|
|
||||||
@property
|
|
||||||
def media_artist(self):
|
|
||||||
"""Artist of current playing media, music track only."""
|
|
||||||
return self._media_artist
|
|
||||||
|
|
||||||
@property
|
|
||||||
def media_title(self):
|
|
||||||
"""Title of current playing media."""
|
|
||||||
return self._media_title
|
|
||||||
|
|
||||||
def turn_on(self) -> None:
|
def turn_on(self) -> None:
|
||||||
"""Turn on specified media player or all."""
|
"""Turn on specified media player or all."""
|
||||||
@ -217,7 +179,7 @@ class UERadioDevice(MediaPlayerEntity):
|
|||||||
def mute_volume(self, mute: bool) -> None:
|
def mute_volume(self, mute: bool) -> None:
|
||||||
"""Send mute command."""
|
"""Send mute command."""
|
||||||
if mute:
|
if mute:
|
||||||
self._last_volume = self._volume
|
self._last_volume = self.volume_level
|
||||||
self.send_command(["mixer", "volume", 0])
|
self.send_command(["mixer", "volume", 0])
|
||||||
else:
|
else:
|
||||||
self.send_command(["mixer", "volume", self._last_volume * 100])
|
self.send_command(["mixer", "volume", self._last_volume * 100])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user