Skip to content

Commit

Permalink
Use shorthand attributes in Volumio (#99918)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Sep 8, 2023
1 parent c6f8766 commit 38247ae
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions homeassistant/components/volumio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,28 @@ class Volumio(MediaPlayerEntity):
| MediaPlayerEntityFeature.CLEAR_PLAYLIST
| MediaPlayerEntityFeature.BROWSE_MEDIA
)
_attr_source_list = []

def __init__(self, volumio, uid, name, info):
"""Initialize the media player."""
self._volumio = volumio
self._uid = uid
self._name = name
self._info = info
unique_id = uid
self._state = {}
self._playlists = []
self._currentplaylist = None
self.thumbnail_cache = {}
self._attr_unique_id = unique_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, unique_id)},
manufacturer="Volumio",
model=info["hardware"],
name=name,
sw_version=info["systemversion"],
)

async def async_update(self) -> None:
"""Update state."""
self._state = await self._volumio.get_state()
await self._async_update_playlists()

@property
def unique_id(self):
"""Return the unique id for the entity."""
return self._uid

@property
def device_info(self) -> DeviceInfo:
"""Return device info for this device."""
return DeviceInfo(
identifiers={(DOMAIN, self.unique_id)},
manufacturer="Volumio",
model=self._info["hardware"],
name=self._name,
sw_version=self._info["systemversion"],
)

@property
def state(self) -> MediaPlayerState:
"""Return the state of the device."""
Expand Down Expand Up @@ -169,16 +158,6 @@ def repeat(self) -> RepeatMode:
return RepeatMode.ALL
return RepeatMode.OFF

@property
def source_list(self):
"""Return the list of available input sources."""
return self._playlists

@property
def source(self):
"""Name of the current input source."""
return self._currentplaylist

async def async_media_next_track(self) -> None:
"""Send media_next command to media player."""
await self._volumio.next()
Expand Down Expand Up @@ -235,17 +214,17 @@ async def async_set_repeat(self, repeat: RepeatMode) -> None:
async def async_select_source(self, source: str) -> None:
"""Choose an available playlist and play it."""
await self._volumio.play_playlist(source)
self._currentplaylist = source
self._attr_source = source

async def async_clear_playlist(self) -> None:
"""Clear players playlist."""
await self._volumio.clear_playlist()
self._currentplaylist = None
self._attr_source = None

@Throttle(PLAYLIST_UPDATE_INTERVAL)
async def _async_update_playlists(self, **kwargs):
"""Update available Volumio playlists."""
self._playlists = await self._volumio.get_playlists()
self._attr_source_list = await self._volumio.get_playlists()

async def async_play_media(
self, media_type: MediaType | str, media_id: str, **kwargs: Any
Expand Down

0 comments on commit 38247ae

Please sign in to comment.