Add media browser integration for Home Assistant
- Implement async_browse_media() to enable browsing media folders through HA Media Browser UI - Add async_play_media() to handle file playback from media browser - Add play_media_file service for automation support - Add BROWSE_MEDIA and PLAY_MEDIA feature flags - Implement media browser API client methods (get_media_folders, browse_folder, play_media_file) - Fix path separator handling for cross-platform compatibility Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,9 @@ from .const import (
|
||||
API_TOGGLE,
|
||||
API_SCRIPTS_LIST,
|
||||
API_SCRIPTS_EXECUTE,
|
||||
API_BROWSER_FOLDERS,
|
||||
API_BROWSER_BROWSE,
|
||||
API_BROWSER_PLAY,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -296,6 +299,49 @@ class MediaServerClient:
|
||||
json_data = {"args": args or []}
|
||||
return await self._request("POST", endpoint, json_data)
|
||||
|
||||
async def get_media_folders(self) -> dict[str, dict[str, Any]]:
|
||||
"""Get configured media folders.
|
||||
|
||||
Returns:
|
||||
Dictionary of folders with folder_id as key and folder config as value
|
||||
"""
|
||||
return await self._request("GET", API_BROWSER_FOLDERS)
|
||||
|
||||
async def browse_folder(
|
||||
self, folder_id: str, path: str = "", offset: int = 0, limit: int = 100
|
||||
) -> dict[str, Any]:
|
||||
"""Browse a media folder.
|
||||
|
||||
Args:
|
||||
folder_id: ID of the folder to browse
|
||||
path: Path within the folder (empty for root)
|
||||
offset: Pagination offset
|
||||
limit: Number of items to return
|
||||
|
||||
Returns:
|
||||
Dictionary with current_path, parent_path, items, total, offset, limit
|
||||
"""
|
||||
params = {
|
||||
"folder_id": folder_id,
|
||||
"path": path,
|
||||
"offset": offset,
|
||||
"limit": limit,
|
||||
}
|
||||
query_string = "&".join(f"{k}={v}" for k, v in params.items())
|
||||
endpoint = f"{API_BROWSER_BROWSE}?{query_string}"
|
||||
return await self._request("GET", endpoint)
|
||||
|
||||
async def play_media_file(self, file_path: str) -> dict[str, Any]:
|
||||
"""Play a media file by absolute path.
|
||||
|
||||
Args:
|
||||
file_path: Absolute path to the media file
|
||||
|
||||
Returns:
|
||||
Response data with success status
|
||||
"""
|
||||
return await self._request("POST", API_BROWSER_PLAY, {"path": file_path})
|
||||
|
||||
|
||||
class MediaServerWebSocket:
|
||||
"""WebSocket client for real-time media status updates."""
|
||||
|
||||
Reference in New Issue
Block a user