1 """Component to embed Google Cast."""
3 from __future__
import annotations
5 from typing
import Protocol
7 from pychromecast
import Chromecast
16 async_process_integration_platforms,
19 from .
import home_assistant_cast
20 from .const
import DOMAIN
22 PLATFORMS = [Platform.MEDIA_PLAYER]
26 """Set up Cast from a config entry."""
27 hass.data[DOMAIN] = {
"cast_platform": {},
"unknown_models": {}}
28 await home_assistant_cast.async_setup_ha_cast(hass, entry)
29 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
35 """Define the format of cast platforms."""
38 self, hass: HomeAssistant, cast_type: str
39 ) -> list[BrowseMedia]:
40 """Create a list of root objects for media browsing."""
45 media_content_type: MediaType | str,
46 media_content_id: str,
48 ) -> BrowseMedia |
None:
51 Return a BrowseMedia object or None if the media does not belong to
59 chromecast: Chromecast,
60 media_type: MediaType | str,
65 Return True if the media is played by the platform, False if not.
71 hass: HomeAssistant, integration_domain: str, platform: CastProtocol
73 """Register a cast platform."""
75 not hasattr(platform,
"async_get_media_browser_root_object")
76 or not hasattr(platform,
"async_browse_media")
77 or not hasattr(platform,
"async_play_media")
80 hass.data[DOMAIN][
"cast_platform"][integration_domain] = platform
84 """Remove Home Assistant Cast user."""
85 await home_assistant_cast.async_remove_user(hass, entry)
89 hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
91 """Remove cast config entry from a device.
93 The actual cleanup is done in CastMediaPlayerEntity.async_will_remove_from_hass.
list[BrowseMedia] async_get_media_browser_root_object(self, HomeAssistant hass, str cast_type)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_remove_config_entry_device(HomeAssistant hass, ConfigEntry config_entry, dr.DeviceEntry device_entry)
None async_remove_entry(HomeAssistant hass, ConfigEntry entry)
def _register_cast_platform(HomeAssistant hass, str integration_domain, CastProtocol platform)
bool async_play_media(HomeAssistant hass, str cast_entity_id, Chromecast chromecast, MediaType|str media_type, str media_id)
def async_browse_media(hass, media_content_type, media_content_id, platform=None)