mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Add MediaSourceProtocol to improve platform typing (#117001)
This commit is contained in:
parent
e5b91aa522
commit
db138f3727
@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
from typing import Any, Protocol
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -58,6 +58,13 @@ __all__ = [
|
||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||
|
||||
|
||||
class MediaSourceProtocol(Protocol):
|
||||
"""Define the format of media_source platforms."""
|
||||
|
||||
async def async_get_media_source(self, hass: HomeAssistant) -> MediaSource:
|
||||
"""Set up media source."""
|
||||
|
||||
|
||||
def is_media_source_id(media_content_id: str) -> bool:
|
||||
"""Test if identifier is a media source."""
|
||||
return URI_SCHEME_REGEX.match(media_content_id) is not None
|
||||
@ -87,7 +94,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
|
||||
async def _process_media_source_platform(
|
||||
hass: HomeAssistant, domain: str, platform: Any
|
||||
hass: HomeAssistant,
|
||||
domain: str,
|
||||
platform: MediaSourceProtocol,
|
||||
) -> None:
|
||||
"""Process a media source platform."""
|
||||
hass.data[DOMAIN][domain] = await platform.async_get_media_source(hass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user