Remove deprecated host & platform configuration for cast (#41402)
parent
9e1461da62
commit
3f263d5cbe
|
@ -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)
|
||||
|
|
|
@ -149,7 +149,7 @@ async def async_setup_media_player_cast(hass: HomeAssistantType, info: Chromecas
|
|||
return_value=zconf,
|
||||
):
|
||||
await async_setup_component(
|
||||
hass, "cast", {"cast": {"media_player": {"host": info.host}}}
|
||||
hass, "cast", {"cast": {"media_player": {"uuid": info.uuid}}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -236,7 +236,7 @@ async def test_create_cast_device_with_uuid(hass):
|
|||
|
||||
async def test_replay_past_chromecasts(hass):
|
||||
"""Test cast platform re-playing past chromecasts when adding new one."""
|
||||
cast_group1 = get_fake_chromecast_info(host="host1", port=8009)
|
||||
cast_group1 = get_fake_chromecast_info(host="host1", port=8009, uuid=FakeUUID)
|
||||
cast_group2 = get_fake_chromecast_info(
|
||||
host="host2", port=8009, uuid=UUID("9462202c-e747-4af5-a66b-7dce0e1ebc09")
|
||||
)
|
||||
|
@ -244,7 +244,7 @@ async def test_replay_past_chromecasts(hass):
|
|||
zconf_2 = get_fake_zconf(host="host2", port=8009)
|
||||
|
||||
discover_cast, add_dev1 = await async_setup_cast_internal_discovery(
|
||||
hass, config={"host": "host1"}
|
||||
hass, config={"uuid": FakeUUID}
|
||||
)
|
||||
|
||||
with patch(
|
||||
|
@ -266,41 +266,11 @@ async def test_replay_past_chromecasts(hass):
|
|||
assert add_dev1.call_count == 1
|
||||
|
||||
add_dev2 = Mock()
|
||||
await cast._async_setup_platform(hass, {"host": "host2"}, add_dev2, None)
|
||||
await cast._async_setup_platform(hass, {"host": "host2"}, add_dev2)
|
||||
await hass.async_block_till_done()
|
||||
assert add_dev2.call_count == 1
|
||||
|
||||
|
||||
async def test_manual_cast_chromecasts_host(hass):
|
||||
"""Test only wanted casts are added for manual configuration."""
|
||||
cast_1 = get_fake_chromecast_info(host="configured_host")
|
||||
cast_2 = get_fake_chromecast_info(host="other_host", uuid=FakeUUID2)
|
||||
zconf_1 = get_fake_zconf(host="configured_host")
|
||||
zconf_2 = get_fake_zconf(host="other_host")
|
||||
|
||||
# Manual configuration of media player with host "configured_host"
|
||||
discover_cast, add_dev1 = await async_setup_cast_internal_discovery(
|
||||
hass, config={"host": "configured_host"}
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
|
||||
return_value=zconf_2,
|
||||
):
|
||||
discover_cast("service2", cast_2)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done() # having tasks that add jobs
|
||||
assert add_dev1.call_count == 0
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.cast.discovery.ChromeCastZeroconf.get_zeroconf",
|
||||
return_value=zconf_1,
|
||||
):
|
||||
discover_cast("service1", cast_1)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done() # having tasks that add jobs
|
||||
assert add_dev1.call_count == 1
|
||||
|
||||
|
||||
async def test_manual_cast_chromecasts_uuid(hass):
|
||||
"""Test only wanted casts are added for manual configuration."""
|
||||
cast_1 = get_fake_chromecast_info(host="host_1", uuid=FakeUUID)
|
||||
|
@ -729,7 +699,7 @@ async def test_entry_setup_no_config(hass: HomeAssistantType):
|
|||
async def test_entry_setup_single_config(hass: HomeAssistantType):
|
||||
"""Test setting up entry and having a single config option."""
|
||||
await async_setup_component(
|
||||
hass, "cast", {"cast": {"media_player": {"host": "bla"}}}
|
||||
hass, "cast", {"cast": {"media_player": {"uuid": "bla"}}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -739,13 +709,13 @@ async def test_entry_setup_single_config(hass: HomeAssistantType):
|
|||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert mock_setup.mock_calls[0][1][1] == {"host": "bla"}
|
||||
assert mock_setup.mock_calls[0][1][1] == {"uuid": "bla"}
|
||||
|
||||
|
||||
async def test_entry_setup_list_config(hass: HomeAssistantType):
|
||||
"""Test setting up entry and having multiple config options."""
|
||||
await async_setup_component(
|
||||
hass, "cast", {"cast": {"media_player": [{"host": "bla"}, {"host": "blu"}]}}
|
||||
hass, "cast", {"cast": {"media_player": [{"uuid": "bla"}, {"uuid": "blu"}]}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -755,14 +725,14 @@ async def test_entry_setup_list_config(hass: HomeAssistantType):
|
|||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||
|
||||
assert len(mock_setup.mock_calls) == 2
|
||||
assert mock_setup.mock_calls[0][1][1] == {"host": "bla"}
|
||||
assert mock_setup.mock_calls[1][1][1] == {"host": "blu"}
|
||||
assert mock_setup.mock_calls[0][1][1] == {"uuid": "bla"}
|
||||
assert mock_setup.mock_calls[1][1][1] == {"uuid": "blu"}
|
||||
|
||||
|
||||
async def test_entry_setup_platform_not_ready(hass: HomeAssistantType):
|
||||
"""Test failed setting up entry will raise PlatformNotReady."""
|
||||
await async_setup_component(
|
||||
hass, "cast", {"cast": {"media_player": {"host": "bla"}}}
|
||||
hass, "cast", {"cast": {"media_player": {"uuid": "bla"}}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -774,4 +744,4 @@ async def test_entry_setup_platform_not_ready(hass: HomeAssistantType):
|
|||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert mock_setup.mock_calls[0][1][1] == {"host": "bla"}
|
||||
assert mock_setup.mock_calls[0][1][1] == {"uuid": "bla"}
|
||||
|
|
Loading…
Reference in New Issue