1 """Fully Kiosk Browser media player."""
3 from __future__
import annotations
13 async_process_play_media_url,
19 from .
import FullyKioskConfigEntry
20 from .const
import AUDIOMANAGER_STREAM_MUSIC, MEDIA_SUPPORT_FULLYKIOSK
21 from .coordinator
import FullyKioskDataUpdateCoordinator
22 from .entity
import FullyKioskEntity
27 config_entry: FullyKioskConfigEntry,
28 async_add_entities: AddEntitiesCallback,
30 """Set up the Fully Kiosk Browser media player entity."""
31 coordinator = config_entry.runtime_data
36 """Representation of a Fully Kiosk Browser media player entity."""
39 _attr_supported_features = MEDIA_SUPPORT_FULLYKIOSK
40 _attr_assumed_state =
True
42 def __init__(self, coordinator: FullyKioskDataUpdateCoordinator) ->
None:
43 """Initialize the media player entity."""
45 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.data['deviceID']}-mediaplayer"
49 self, media_type: MediaType | str, media_id: str, **kwargs: Any
51 """Play a piece of media."""
52 if media_source.is_media_source_id(media_id):
53 play_item = await media_source.async_resolve_media(
58 if media_type.startswith(
"audio/"):
59 media_type = MediaType.MUSIC
60 elif media_type.startswith(
"video/"):
61 media_type = MediaType.VIDEO
62 if media_type == MediaType.MUSIC:
64 await self.coordinator.fully.playSound(media_id, AUDIOMANAGER_STREAM_MUSIC)
65 elif media_type == MediaType.VIDEO:
67 await self.coordinator.fully.sendCommand(
70 stream=AUDIOMANAGER_STREAM_MUSIC,
76 self.
_attr_state_attr_state = MediaPlayerState.PLAYING
80 """Stop playing media."""
82 await self.coordinator.fully.sendCommand(
"stopVideo")
84 await self.coordinator.fully.stopSound()
89 """Set volume level, range 0..1."""
90 await self.coordinator.fully.setAudioVolume(
91 int(volume * 100), AUDIOMANAGER_STREAM_MUSIC
98 media_content_type: MediaType | str |
None =
None,
99 media_content_id: str |
None =
None,
101 """Implement the WebSocket media browsing helper."""
102 return await media_source.async_browse_media(
105 content_filter=
lambda item: item.media_content_type.startswith(
"audio/")
106 or item.media_content_type.startswith(
"video/"),
111 """Handle updated data from the coordinator."""
113 MediaPlayerState.PLAYING
114 if "soundUrlPlaying" in self.coordinator.data
115 else MediaPlayerState.IDLE
None async_write_ha_state(self)