Remove deprecated host & platform configuration for cast (#41402)

This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-10-07 18:01:34 +02:00
1 parent 9e1461da62
commit 3f263d5cbe
2 files changed
+20 -88

No files matched your search

+9 -47
View File
@@ -19,7 +19,7 @@ import voluptuous as vol
from homeassistant.auth.models import RefreshToken
from homeassistant.components import media_source, zeroconf
from homeassistant.components.http.auth import async_sign_path
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.components.media_player.const import (
ATTR_MEDIA_EXTRA,
MEDIA_TYPE_MOVIE,
@@ -39,7 +39,6 @@ from homeassistant.components.media_player.const import (
SUPPORT_VOLUME_SET,
)
from homeassistant.const import (
CONF_HOST,
EVENT_HOMEASSISTANT_STOP,
STATE_IDLE,
STATE_OFF,
@@ -58,7 +57,6 @@ from homeassistant.util.logging import async_create_catching_coro
from .const import (
ADDED_CAST_DEVICES_KEY,
CAST_MULTIZONE_MANAGER_KEY,
DEFAULT_PORT,
DOMAIN as CAST_DOMAIN,
KNOWN_CHROMECAST_INFO_KEY,
SIGNAL_CAST_DISCOVERED,
@@ -86,22 +84,9 @@ SUPPORT_CAST = (
ENTITY_SCHEMA = vol.All(
cv.deprecated(CONF_HOST),
vol.Schema(
{
vol.Exclusive(CONF_HOST, "device_identifier"): cv.string,
vol.Exclusive(CONF_UUID, "device_identifier"): cv.string,
vol.Optional(CONF_IGNORE_CEC): vol.All(cv.ensure_list, [cv.string]),
}
),
)
PLATFORM_SCHEMA = vol.All(
cv.deprecated(CONF_HOST),
PLATFORM_SCHEMA.extend(
{
vol.Exclusive(CONF_HOST, "device_identifier"): cv.string,
vol.Exclusive(CONF_UUID, "device_identifier"): cv.string,
vol.Optional(CONF_UUID): cv.string,
vol.Optional(CONF_IGNORE_CEC): vol.All(cv.ensure_list, [cv.string]),
}
),
@@ -130,21 +115,6 @@ def _async_create_cast_device(hass: HomeAssistantType, info: ChromecastInfo):
return CastDevice(info)
async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
):
"""Set up the Cast platform.
Deprecated.
"""
_LOGGER.warning(
"Setting configuration for Cast via platform is deprecated. "
"Configure via Cast integration instead."
"This option will become invalid in version 0.116"
)
await _async_setup_platform(hass, config, async_add_entities, discovery_info)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Cast from a config entry."""
config = hass.data[CAST_DOMAIN].get("media_player") or {}
@@ -154,11 +124,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
# no pending task
done, _ = await asyncio.wait(
[
_async_setup_platform(hass, ENTITY_SCHEMA(cfg), async_add_entities, None)
_async_setup_platform(hass, ENTITY_SCHEMA(cfg), async_add_entities)
for cfg in config
]
)
if any([task.exception() for task in done]):
if any(task.exception() for task in done):
exceptions = [task.exception() for task in done]
for exception in exceptions:
_LOGGER.debug("Failed to setup chromecast", exc_info=exception)
@@ -166,7 +136,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async def _async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info
hass: HomeAssistantType, config: ConfigType, async_add_entities
):
"""Set up the cast platform."""
# Import CEC IGNORE attributes
@@ -175,23 +145,15 @@ async def _async_setup_platform(
hass.data.setdefault(KNOWN_CHROMECAST_INFO_KEY, {})
info = None
if discovery_info is not None:
info = ChromecastInfo(
host=discovery_info["host"], port=discovery_info["port"], services=None
)
elif CONF_UUID in config:
if CONF_UUID in config:
info = ChromecastInfo(uuid=config[CONF_UUID], services=None)
elif CONF_HOST in config:
info = ChromecastInfo(host=config[CONF_HOST], port=DEFAULT_PORT, services=None)
@callback
def async_cast_discovered(discover: ChromecastInfo) -> None:
"""Handle discovery of a new chromecast."""
if info is not None and (
(info.uuid is not None and info.uuid != discover.uuid)
or (info.host is not None and info.host_port != discover.host_port)
):
# Waiting for a specific cast device, this is not it.
# If info is set, we're handling a specific cast device identified by UUID
if info is not None and (info.uuid is not None and info.uuid != discover.uuid):
# UUID not matching, this is not it.
return
cast_device = _async_create_cast_device(hass, discover)