Skip to content

Commit 88e6b0c

Browse files
authored
Make LocalSource reusable (home-assistant#151886)
1 parent 2ed92c7 commit 88e6b0c

File tree

3 files changed

+156
-100
lines changed

3 files changed

+156
-100
lines changed

homeassistant/components/media_source/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
8585
frontend.async_register_built_in_panel(
8686
hass, "media-browser", "media_browser", "hass:play-box-multiple"
8787
)
88-
local_source.async_setup(hass)
88+
89+
# Local sources support
90+
await _process_media_source_platform(hass, DOMAIN, local_source)
91+
hass.http.register_view(local_source.UploadMediaView)
92+
websocket_api.async_register_command(hass, local_source.websocket_remove_media)
93+
8994
await async_process_integration_platforms(
9095
hass, DOMAIN, _process_media_source_platform
9196
)
@@ -98,7 +103,10 @@ async def _process_media_source_platform(
98103
platform: MediaSourceProtocol,
99104
) -> None:
100105
"""Process a media source platform."""
101-
hass.data[MEDIA_SOURCE_DATA][domain] = await platform.async_get_media_source(hass)
106+
source = await platform.async_get_media_source(hass)
107+
hass.data[MEDIA_SOURCE_DATA][domain] = source
108+
if isinstance(source, local_source.LocalSource):
109+
hass.http.register_view(local_source.LocalMediaView(hass, source))
102110

103111

104112
@callback

0 commit comments

Comments
 (0)