Use entity class attributes for cmus (#53458)
This commit is contained in:
parent
3f7cc176a8
commit
86b126c34a
1 changed files with 24 additions and 71 deletions
|
@ -98,6 +98,9 @@ class CmusRemote:
|
|||
class CmusDevice(MediaPlayerEntity):
|
||||
"""Representation of a running cmus."""
|
||||
|
||||
_attr_media_content_type = MEDIA_TYPE_MUSIC
|
||||
_attr_supported_features = SUPPORT_CMUS
|
||||
|
||||
def __init__(self, device, name, server):
|
||||
"""Initialize the CMUS device."""
|
||||
|
||||
|
@ -106,7 +109,7 @@ class CmusDevice(MediaPlayerEntity):
|
|||
auto_name = f"cmus-{server}"
|
||||
else:
|
||||
auto_name = "cmus-local"
|
||||
self._name = name or auto_name
|
||||
self._attr_name = name or auto_name
|
||||
self.status = {}
|
||||
|
||||
def update(self):
|
||||
|
@ -120,79 +123,29 @@ class CmusDevice(MediaPlayerEntity):
|
|||
self._remote.connect()
|
||||
else:
|
||||
self.status = status
|
||||
return
|
||||
|
||||
_LOGGER.warning("Received no status from cmus")
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the media state."""
|
||||
if self.status.get("status") == "playing":
|
||||
return STATE_PLAYING
|
||||
if self.status.get("status") == "paused":
|
||||
return STATE_PAUSED
|
||||
return STATE_OFF
|
||||
|
||||
@property
|
||||
def media_content_id(self):
|
||||
"""Content ID of current playing media."""
|
||||
return self.status.get("file")
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
"""Content type of the current playing media."""
|
||||
return MEDIA_TYPE_MUSIC
|
||||
|
||||
@property
|
||||
def media_duration(self):
|
||||
"""Duration of current playing media in seconds."""
|
||||
return self.status.get("duration")
|
||||
|
||||
@property
|
||||
def media_title(self):
|
||||
"""Title of current playing media."""
|
||||
return self.status["tag"].get("title")
|
||||
|
||||
@property
|
||||
def media_artist(self):
|
||||
"""Artist of current playing media, music track only."""
|
||||
return self.status["tag"].get("artist")
|
||||
|
||||
@property
|
||||
def media_track(self):
|
||||
"""Track number of current playing media, music track only."""
|
||||
return self.status["tag"].get("tracknumber")
|
||||
|
||||
@property
|
||||
def media_album_name(self):
|
||||
"""Album name of current playing media, music track only."""
|
||||
return self.status["tag"].get("album")
|
||||
|
||||
@property
|
||||
def media_album_artist(self):
|
||||
"""Album artist of current playing media, music track only."""
|
||||
return self.status["tag"].get("albumartist")
|
||||
|
||||
@property
|
||||
def volume_level(self):
|
||||
"""Return the volume level."""
|
||||
self._attr_state = STATE_PLAYING
|
||||
elif self.status.get("status") == "paused":
|
||||
self._attr_state = STATE_PAUSED
|
||||
else:
|
||||
self._attr_state = STATE_OFF
|
||||
self._attr_media_content_id = self.status.get("file")
|
||||
self._attr_media_duration = self.status.get("duration")
|
||||
self._attr_media_title = self.status["tag"].get("title")
|
||||
self._attr_media_artist = self.status["tag"].get("artist")
|
||||
self._attr_media_track = self.status["tag"].get("tracknumber")
|
||||
self._attr_media_album_name = self.status["tag"].get("album")
|
||||
self._attr_media_album_artist = self.status["tag"].get("albumartist")
|
||||
left = self.status["set"].get("vol_left")[0]
|
||||
right = self.status["set"].get("vol_right")[0]
|
||||
if left != right:
|
||||
volume = float(left + right) / 2
|
||||
else:
|
||||
volume = left
|
||||
return int(volume) / 100
|
||||
self._attr_volume_level = int(volume) / 100
|
||||
return
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag media player features that are supported."""
|
||||
return SUPPORT_CMUS
|
||||
_LOGGER.warning("Received no status from cmus")
|
||||
|
||||
def turn_off(self):
|
||||
"""Service to send the CMUS the command to stop playing."""
|
||||
|
|
Loading…
Add table
Reference in a new issue