2018-06-14 19:17:54 +00:00
|
|
|
"""Component to embed Google Cast."""
|
2021-03-25 13:06:01 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2021-12-29 11:30:16 +00:00
|
|
|
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
2021-12-04 07:57:24 +00:00
|
|
|
from homeassistant.const import Platform
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-03-25 13:06:01 +00:00
|
|
|
from homeassistant.helpers import config_validation as cv
|
2021-12-29 11:30:16 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2018-06-14 19:17:54 +00:00
|
|
|
|
2019-09-11 18:34:10 +00:00
|
|
|
from . import home_assistant_cast
|
2019-05-13 08:16:55 +00:00
|
|
|
from .const import DOMAIN
|
2021-03-25 13:06:01 +00:00
|
|
|
from .media_player import ENTITY_SCHEMA
|
|
|
|
|
2021-12-21 11:46:10 +00:00
|
|
|
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
2021-03-25 13:06:01 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2018-06-14 19:17:54 +00:00
|
|
|
|
2021-12-04 07:57:24 +00:00
|
|
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
|
|
|
|
2018-06-14 19:17:54 +00:00
|
|
|
|
2021-12-29 11:30:16 +00:00
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
2018-06-14 19:17:54 +00:00
|
|
|
"""Set up the Cast component."""
|
2021-10-18 16:36:35 +00:00
|
|
|
if (conf := config.get(DOMAIN)) is not None:
|
2021-03-25 13:06:01 +00:00
|
|
|
media_player_config_validated = []
|
|
|
|
media_player_config = conf.get("media_player", {})
|
|
|
|
if not isinstance(media_player_config, list):
|
|
|
|
media_player_config = [media_player_config]
|
|
|
|
for cfg in media_player_config:
|
|
|
|
try:
|
|
|
|
cfg = ENTITY_SCHEMA(cfg)
|
|
|
|
media_player_config_validated.append(cfg)
|
|
|
|
except vol.Error as ex:
|
|
|
|
_LOGGER.warning("Invalid config '%s': %s", cfg, ex)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.flow.async_init(
|
2021-03-25 13:06:01 +00:00
|
|
|
DOMAIN,
|
2021-12-29 11:30:16 +00:00
|
|
|
context={"source": SOURCE_IMPORT},
|
2021-03-25 13:06:01 +00:00
|
|
|
data=media_player_config_validated,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
|
|
|
)
|
2018-07-23 13:08:03 +00:00
|
|
|
|
2018-06-14 19:17:54 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-12-29 11:30:16 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2018-06-14 19:17:54 +00:00
|
|
|
"""Set up Cast from a config entry."""
|
2019-09-11 18:34:10 +00:00
|
|
|
await home_assistant_cast.async_setup_ha_cast(hass, entry)
|
2021-12-04 07:57:24 +00:00
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
2018-06-14 19:17:54 +00:00
|
|
|
return True
|
2020-12-16 10:00:22 +00:00
|
|
|
|
|
|
|
|
2021-12-29 11:30:16 +00:00
|
|
|
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
2020-12-16 10:00:22 +00:00
|
|
|
"""Remove Home Assistant Cast user."""
|
|
|
|
await home_assistant_cast.async_remove_user(hass, entry)
|