2021-04-01 13:13:58 +00:00
|
|
|
"""Tests for the Cast integration."""
|
|
|
|
from unittest.mock import patch
|
2018-06-14 19:17:54 +00:00
|
|
|
|
|
|
|
from homeassistant.components import cast
|
2019-12-08 16:30:57 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-06-14 19:17:54 +00:00
|
|
|
|
2018-07-23 13:08:03 +00:00
|
|
|
|
2021-03-25 13:06:01 +00:00
|
|
|
async def test_import(hass, caplog):
|
2018-07-23 13:08:03 +00:00
|
|
|
"""Test that specifying config will create an entry."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
2020-04-30 23:31:00 +00:00
|
|
|
"homeassistant.components.cast.async_setup_entry", return_value=True
|
2020-07-29 21:46:14 +00:00
|
|
|
) as mock_setup:
|
2019-07-31 19:25:30 +00:00
|
|
|
await async_setup_component(
|
2021-03-25 13:06:01 +00:00
|
|
|
hass,
|
|
|
|
cast.DOMAIN,
|
|
|
|
{
|
|
|
|
"cast": {
|
|
|
|
"media_player": [
|
|
|
|
{"uuid": "abcd"},
|
|
|
|
{"uuid": "abcd", "ignore_cec": "milk"},
|
|
|
|
{"uuid": "efgh", "ignore_cec": "beer"},
|
|
|
|
{"incorrect": "config"},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-07-23 13:08:03 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_setup.mock_calls) == 1
|
|
|
|
|
2021-03-25 13:06:01 +00:00
|
|
|
assert len(hass.config_entries.async_entries("cast")) == 1
|
|
|
|
entry = hass.config_entries.async_entries("cast")[0]
|
|
|
|
assert set(entry.data["ignore_cec"]) == {"milk", "beer"}
|
|
|
|
assert set(entry.data["uuid"]) == {"abcd", "efgh"}
|
|
|
|
|
|
|
|
assert "Invalid config '{'incorrect': 'config'}'" in caplog.text
|
|
|
|
|
2018-07-23 13:08:03 +00:00
|
|
|
|
|
|
|
async def test_not_configuring_cast_not_creates_entry(hass):
|
2021-04-01 13:13:58 +00:00
|
|
|
"""Test that an empty config does not create an entry."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
2020-04-30 23:31:00 +00:00
|
|
|
"homeassistant.components.cast.async_setup_entry", return_value=True
|
2020-07-29 21:46:14 +00:00
|
|
|
) as mock_setup:
|
2018-07-23 13:08:03 +00:00
|
|
|
await async_setup_component(hass, cast.DOMAIN, {})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_setup.mock_calls) == 0
|