mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use shorthand attributes in Volumio (#99918)
This commit is contained in:
parent
c6f8766b1e
commit
38247ae868
@ -69,39 +69,28 @@ class Volumio(MediaPlayerEntity):
|
|||||||
| MediaPlayerEntityFeature.CLEAR_PLAYLIST
|
| MediaPlayerEntityFeature.CLEAR_PLAYLIST
|
||||||
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
|
_attr_source_list = []
|
||||||
|
|
||||||
def __init__(self, volumio, uid, name, info):
|
def __init__(self, volumio, uid, name, info):
|
||||||
"""Initialize the media player."""
|
"""Initialize the media player."""
|
||||||
self._volumio = volumio
|
self._volumio = volumio
|
||||||
self._uid = uid
|
unique_id = uid
|
||||||
self._name = name
|
|
||||||
self._info = info
|
|
||||||
self._state = {}
|
self._state = {}
|
||||||
self._playlists = []
|
|
||||||
self._currentplaylist = None
|
|
||||||
self.thumbnail_cache = {}
|
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:
|
async def async_update(self) -> None:
|
||||||
"""Update state."""
|
"""Update state."""
|
||||||
self._state = await self._volumio.get_state()
|
self._state = await self._volumio.get_state()
|
||||||
await self._async_update_playlists()
|
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
|
@property
|
||||||
def state(self) -> MediaPlayerState:
|
def state(self) -> MediaPlayerState:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
@ -169,16 +158,6 @@ class Volumio(MediaPlayerEntity):
|
|||||||
return RepeatMode.ALL
|
return RepeatMode.ALL
|
||||||
return RepeatMode.OFF
|
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:
|
async def async_media_next_track(self) -> None:
|
||||||
"""Send media_next command to media player."""
|
"""Send media_next command to media player."""
|
||||||
await self._volumio.next()
|
await self._volumio.next()
|
||||||
@ -235,17 +214,17 @@ class Volumio(MediaPlayerEntity):
|
|||||||
async def async_select_source(self, source: str) -> None:
|
async def async_select_source(self, source: str) -> None:
|
||||||
"""Choose an available playlist and play it."""
|
"""Choose an available playlist and play it."""
|
||||||
await self._volumio.play_playlist(source)
|
await self._volumio.play_playlist(source)
|
||||||
self._currentplaylist = source
|
self._attr_source = source
|
||||||
|
|
||||||
async def async_clear_playlist(self) -> None:
|
async def async_clear_playlist(self) -> None:
|
||||||
"""Clear players playlist."""
|
"""Clear players playlist."""
|
||||||
await self._volumio.clear_playlist()
|
await self._volumio.clear_playlist()
|
||||||
self._currentplaylist = None
|
self._attr_source = None
|
||||||
|
|
||||||
@Throttle(PLAYLIST_UPDATE_INTERVAL)
|
@Throttle(PLAYLIST_UPDATE_INTERVAL)
|
||||||
async def _async_update_playlists(self, **kwargs):
|
async def _async_update_playlists(self, **kwargs):
|
||||||
"""Update available Volumio playlists."""
|
"""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(
|
async def async_play_media(
|
||||||
self, media_type: MediaType | str, media_id: str, **kwargs: Any
|
self, media_type: MediaType | str, media_id: str, **kwargs: Any
|
||||||
|
Loading…
x
Reference in New Issue
Block a user