1 """Provide functionality to interact with vlc devices on the network."""
3 from __future__
import annotations
9 import voluptuous
as vol
13 PLATFORM_SCHEMA
as MEDIA_PLAYER_PLATFORM_SCHEMA,
16 MediaPlayerEntityFeature,
19 async_process_play_media_url,
28 _LOGGER = logging.getLogger(__name__)
30 CONF_ARGUMENTS =
"arguments"
33 PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
35 vol.Optional(CONF_ARGUMENTS, default=
""): cv.string,
36 vol.Optional(CONF_NAME): cv.string,
44 add_entities: AddEntitiesCallback,
45 discovery_info: DiscoveryInfoType |
None =
None,
47 """Set up the vlc platform."""
49 [
VlcDevice(config.get(CONF_NAME, DEFAULT_NAME), config.get(CONF_ARGUMENTS))]
54 """Representation of a vlc player."""
56 _attr_media_content_type = MediaType.MUSIC
57 _attr_supported_features = (
58 MediaPlayerEntityFeature.PAUSE
59 | MediaPlayerEntityFeature.VOLUME_SET
60 | MediaPlayerEntityFeature.VOLUME_MUTE
61 | MediaPlayerEntityFeature.PLAY_MEDIA
62 | MediaPlayerEntityFeature.PLAY
63 | MediaPlayerEntityFeature.STOP
64 | MediaPlayerEntityFeature.BROWSE_MEDIA
68 """Initialize the vlc device."""
74 """Get the latest details from the device."""
76 if status == vlc.State.Playing:
78 elif status == vlc.State.Paused:
79 self.
_attr_state_attr_state = MediaPlayerState.PAUSED
94 """Seek the media to a specific location."""
95 track_length = self.
_vlc_vlc.get_length() / 1000
96 self.
_vlc_vlc.set_position(position / track_length)
99 """Mute the volume."""
100 self.
_vlc_vlc.audio_set_mute(mute)
104 """Set volume level, range 0..1."""
105 self.
_vlc_vlc.audio_set_volume(
int(volume * 100))
109 """Send play command."""
111 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
114 """Send pause command."""
115 self.
_vlc_vlc.pause()
116 self.
_attr_state_attr_state = MediaPlayerState.PAUSED
119 """Send stop command."""
121 self.
_attr_state_attr_state = MediaPlayerState.IDLE
124 self, media_type: MediaType | str, media_id: str, **kwargs: Any
126 """Play media from a URL or file."""
128 if media_source.is_media_source_id(media_id):
129 sourced_media = await media_source.async_resolve_media(
132 media_id = sourced_media.url
134 elif media_type != MediaType.MUSIC:
136 "Invalid media type %s. Only %s is supported",
145 self.
_vlc_vlc.set_media(self.
_instance_instance.media_new(media_id))
148 await self.
hasshass.async_add_executor_job(play)
149 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
153 media_content_type: MediaType | str |
None =
None,
154 media_content_id: str |
None =
None,
156 """Implement the websocket media browsing helper."""
157 return await media_source.async_browse_media(
160 content_filter=
lambda item: item.media_content_type.startswith(
"audio/"),
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
str|float get_state(dict[str, float] data, str key)