3 Volumio rest API: https://volumio.github.io/docs/API/REST_API.html
6 from __future__
import annotations
8 from datetime
import timedelta
10 from typing
import Any
15 MediaPlayerEntityFeature,
27 from .browse_media
import browse_node, browse_top_level
28 from .const
import DATA_INFO, DATA_VOLUMIO, DOMAIN
35 config_entry: ConfigEntry,
36 async_add_entities: AddEntitiesCallback,
38 """Set up the Volumio media player platform."""
40 data = hass.data[DOMAIN][config_entry.entry_id]
41 volumio = data[DATA_VOLUMIO]
42 info = data[DATA_INFO]
43 uid = config_entry.data[CONF_ID]
44 name = config_entry.data[CONF_NAME]
46 entity =
Volumio(volumio, uid, name, info)
51 """Volumio Player Object."""
53 _attr_has_entity_name =
True
55 _attr_media_content_type = MediaType.MUSIC
56 _attr_supported_features = (
57 MediaPlayerEntityFeature.PAUSE
58 | MediaPlayerEntityFeature.VOLUME_SET
59 | MediaPlayerEntityFeature.VOLUME_MUTE
60 | MediaPlayerEntityFeature.PREVIOUS_TRACK
61 | MediaPlayerEntityFeature.NEXT_TRACK
62 | MediaPlayerEntityFeature.SEEK
63 | MediaPlayerEntityFeature.STOP
64 | MediaPlayerEntityFeature.PLAY
65 | MediaPlayerEntityFeature.PLAY_MEDIA
66 | MediaPlayerEntityFeature.VOLUME_STEP
67 | MediaPlayerEntityFeature.SELECT_SOURCE
68 | MediaPlayerEntityFeature.REPEAT_SET
69 | MediaPlayerEntityFeature.SHUFFLE_SET
70 | MediaPlayerEntityFeature.CLEAR_PLAYLIST
71 | MediaPlayerEntityFeature.BROWSE_MEDIA
73 _attr_source_list = []
76 """Initialize the media player."""
83 identifiers={(DOMAIN, unique_id)},
84 manufacturer=
"Volumio",
85 model=info[
"hardware"],
87 sw_version=info[
"systemversion"],
96 def state(self) -> MediaPlayerState:
97 """Return the state of the device."""
98 status = self.
_state_state.
get(
"status",
None)
100 return MediaPlayerState.PAUSED
102 return MediaPlayerState.PLAYING
104 return MediaPlayerState.IDLE
108 """Title of current playing media."""
109 return self.
_state_state.
get(
"title",
None)
113 """Artist of current playing media (Music track only)."""
114 return self.
_state_state.
get(
"artist",
None)
118 """Artist of current playing media (Music track only)."""
119 return self.
_state_state.
get(
"album",
None)
123 """Image url of current playing media."""
124 url = self.
_state_state.
get(
"albumart",
None)
125 return self.
_volumio_volumio.canonic_url(url)
129 """Time in seconds of current seek position."""
130 return self.
_state_state.
get(
"seek",
None)
134 """Time in seconds of current song duration."""
135 return self.
_state_state.
get(
"duration",
None)
139 """Volume level of the media player (0..1)."""
140 volume = self.
_state_state.
get(
"volume",
None)
141 if volume
is not None and volume !=
"":
142 volume =
int(volume) / 100
147 """Boolean if volume is currently muted."""
148 return self.
_state_state.
get(
"mute",
None)
152 """Boolean if shuffle is enabled."""
153 return self.
_state_state.
get(
"random",
False)
157 """Return current repeat mode."""
158 if self.
_state_state.
get(
"repeat",
None):
159 return RepeatMode.ALL
160 return RepeatMode.OFF
163 """Send media_next command to media player."""
167 """Send media_previous command to media player."""
168 await self.
_volumio_volumio.previous()
171 """Send media_play command to media player."""
175 """Send media_pause command to media player."""
176 if self.
_state_state.
get(
"trackType") ==
"webradio":
182 """Send media_stop command to media player."""
186 """Send volume_up command to media player."""
190 """Service to send the Volumio the command for volume up."""
191 await self.
_volumio_volumio.volume_up()
194 """Service to send the Volumio the command for volume down."""
195 await self.
_volumio_volumio.volume_down()
198 """Send mute command to media player."""
202 await self.
_volumio_volumio.unmute()
205 """Enable/disable shuffle mode."""
209 """Set repeat mode."""
210 if repeat == RepeatMode.OFF:
211 await self.
_volumio_volumio.repeatAll(
"false")
213 await self.
_volumio_volumio.repeatAll(
"true")
216 """Choose an available playlist and play it."""
217 await self.
_volumio_volumio.play_playlist(source)
221 """Clear players playlist."""
225 @Throttle(PLAYLIST_UPDATE_INTERVAL)
227 """Update available Volumio playlists."""
231 self, media_type: MediaType | str, media_id: str, **kwargs: Any
233 """Send the play_media command to the media player."""
234 await self.
_volumio_volumio.replace_and_play(json.loads(media_id))
238 media_content_type: MediaType | str |
None =
None,
239 media_content_id: str |
None =
None,
241 """Implement the websocket media browsing helper."""
243 if media_content_type
in (
None,
"library"):
247 self, self.
_volumio_volumio, media_content_type, media_content_id
252 media_content_type: MediaType | str,
253 media_content_id: str,
254 media_image_id: str |
None =
None,
255 ) -> tuple[bytes |
None, str |
None]:
256 """Get album art from Volumio."""
258 image_url = self.
_volumio_volumio.canonic_url(cached_url)
web.Response get(self, web.Request request, str config_key)
str|float get_state(dict[str, float] data, str key)