Add MediaSourceProtocol to improve platform typing (#117001)

This commit is contained in:
Marc Mueller 2024-05-07 21:18:11 +02:00 committed by GitHub
parent e5b91aa522
commit db138f3727
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)