Add tests for Roku (#34380)
This commit is contained in:
1 parent
3b12fd22a4
commit
b3eba49a2f
13 files changed
+520
-105
No files matched your search
@@ -1,49 +1,59 @@
|
||||
"""Tests for the Roku component."""
|
||||
from requests_mock import Mocker
|
||||
|
||||
from homeassistant.components.roku.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
HOST = "1.2.3.4"
|
||||
HOST = "192.168.1.160"
|
||||
NAME = "Roku 3"
|
||||
SSDP_LOCATION = "http://1.2.3.4/"
|
||||
SSDP_LOCATION = "http://192.168.1.160/"
|
||||
UPNP_FRIENDLY_NAME = "My Roku 3"
|
||||
UPNP_SERIAL = "1GU48T017973"
|
||||
|
||||
|
||||
class MockDeviceInfo:
|
||||
"""Mock DeviceInfo for Roku."""
|
||||
def mock_connection(
|
||||
requests_mocker: Mocker, device: str = "roku3", app: str = "roku", host: str = HOST,
|
||||
) -> None:
|
||||
"""Mock the Roku connection."""
|
||||
roku_url = f"http://{host}:8060"
|
||||
|
||||
model_name = NAME
|
||||
model_num = "4200X"
|
||||
software_version = "7.5.0.09021"
|
||||
serial_num = UPNP_SERIAL
|
||||
user_device_name = UPNP_FRIENDLY_NAME
|
||||
roku_type = "Box"
|
||||
requests_mocker.get(
|
||||
f"{roku_url}/query/device-info",
|
||||
text=load_fixture(f"roku/{device}-device-info.xml"),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
"""Return the object representation of DeviceInfo."""
|
||||
return "<DeviceInfo: {}-{}, SW v{}, Ser# {} ({})>".format(
|
||||
self.model_name,
|
||||
self.model_num,
|
||||
self.software_version,
|
||||
self.serial_num,
|
||||
self.roku_type,
|
||||
)
|
||||
apps_fixture = "roku/apps.xml"
|
||||
if device == "rokutv":
|
||||
apps_fixture = "roku/apps-tv.xml"
|
||||
|
||||
requests_mocker.get(
|
||||
f"{roku_url}/query/apps", text=load_fixture(apps_fixture),
|
||||
)
|
||||
|
||||
requests_mocker.get(
|
||||
f"{roku_url}/query/active-app", text=load_fixture(f"roku/active-app-{app}.xml"),
|
||||
)
|
||||
|
||||
|
||||
async def setup_integration(
|
||||
hass: HomeAssistantType, skip_entry_setup: bool = False
|
||||
hass: HomeAssistantType,
|
||||
requests_mocker: Mocker,
|
||||
device: str = "roku3",
|
||||
app: str = "roku",
|
||||
host: str = HOST,
|
||||
unique_id: str = UPNP_SERIAL,
|
||||
skip_entry_setup: bool = False,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Roku integration in Home Assistant."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN, unique_id=UPNP_SERIAL, data={CONF_HOST: HOST}
|
||||
)
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id, data={CONF_HOST: host})
|
||||
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
if not skip_entry_setup:
|
||||
mock_connection(requests_mocker, device, app=app, host=host)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""Test the Roku config flow."""
|
||||
from socket import gaierror as SocketGIAError
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from asynctest import patch
|
||||
from requests.exceptions import RequestException
|
||||
from requests_mock import Mocker
|
||||
from roku import RokuException
|
||||
|
||||
from homeassistant.components.roku.const import DOMAIN
|
||||
@@ -27,91 +27,74 @@ from tests.components.roku import (
|
||||
SSDP_LOCATION,
|
||||
UPNP_FRIENDLY_NAME,
|
||||
UPNP_SERIAL,
|
||||
MockDeviceInfo,
|
||||
mock_connection,
|
||||
setup_integration,
|
||||
)
|
||||
|
||||
|
||||
async def async_configure_flow(
|
||||
hass: HomeAssistantType, flow_id: str, user_input: Optional[Dict] = None
|
||||
) -> Any:
|
||||
"""Set up mock Roku integration flow."""
|
||||
with patch(
|
||||
"homeassistant.components.roku.config_flow.Roku.device_info",
|
||||
new=MockDeviceInfo,
|
||||
):
|
||||
return await hass.config_entries.flow.async_configure(
|
||||
flow_id=flow_id, user_input=user_input
|
||||
)
|
||||
|
||||
|
||||
async def async_init_flow(
|
||||
hass: HomeAssistantType,
|
||||
handler: str = DOMAIN,
|
||||
context: Optional[Dict] = None,
|
||||
data: Any = None,
|
||||
) -> Any:
|
||||
"""Set up mock Roku integration flow."""
|
||||
with patch(
|
||||
"homeassistant.components.roku.config_flow.Roku.device_info",
|
||||
new=MockDeviceInfo,
|
||||
):
|
||||
return await hass.config_entries.flow.async_init(
|
||||
handler=handler, context=context, data=data
|
||||
)
|
||||
|
||||
|
||||
async def test_duplicate_error(hass: HomeAssistantType) -> None:
|
||||
async def test_duplicate_error(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
await setup_integration(hass, skip_entry_setup=True)
|
||||
await setup_integration(hass, requests_mock, skip_entry_setup=True)
|
||||
|
||||
result = await async_init_flow(
|
||||
hass, context={CONF_SOURCE: SOURCE_IMPORT}, data={CONF_HOST: HOST}
|
||||
mock_connection(requests_mock)
|
||||
|
||||
user_input = {CONF_HOST: HOST}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
result = await async_init_flow(
|
||||
hass, context={CONF_SOURCE: SOURCE_USER}, data={CONF_HOST: HOST}
|
||||
user_input = {CONF_HOST: HOST}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER}, data=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
result = await async_init_flow(
|
||||
hass,
|
||||
context={CONF_SOURCE: SOURCE_SSDP},
|
||||
data={
|
||||
ATTR_UPNP_FRIENDLY_NAME: UPNP_FRIENDLY_NAME,
|
||||
ATTR_SSDP_LOCATION: SSDP_LOCATION,
|
||||
ATTR_UPNP_SERIAL: UPNP_SERIAL,
|
||||
},
|
||||
discovery_info = {
|
||||
ATTR_UPNP_FRIENDLY_NAME: UPNP_FRIENDLY_NAME,
|
||||
ATTR_SSDP_LOCATION: SSDP_LOCATION,
|
||||
ATTR_UPNP_SERIAL: UPNP_SERIAL,
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_SSDP}, data=discovery_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistantType) -> None:
|
||||
async def test_form(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test the user step."""
|
||||
await async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
mock_connection(requests_mock)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
user_input = {CONF_HOST: HOST}
|
||||
with patch(
|
||||
"homeassistant.components.roku.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.roku.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await async_configure_flow(hass, result["flow_id"], {CONF_HOST: HOST})
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
flow_id=result["flow_id"], user_input=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
assert result["data"] == {CONF_HOST: HOST}
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
@@ -144,12 +127,13 @@ async def test_form_cannot_connect_request(hass: HomeAssistantType) -> None:
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER}
|
||||
)
|
||||
|
||||
user_input = {CONF_HOST: HOST}
|
||||
with patch(
|
||||
"homeassistant.components.roku.config_flow.Roku._call",
|
||||
side_effect=RequestException,
|
||||
) as mock_validate_input:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
flow_id=result["flow_id"], user_input={CONF_HOST: HOST}
|
||||
flow_id=result["flow_id"], user_input=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
@@ -165,12 +149,13 @@ async def test_form_cannot_connect_socket(hass: HomeAssistantType) -> None:
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER}
|
||||
)
|
||||
|
||||
user_input = {CONF_HOST: HOST}
|
||||
with patch(
|
||||
"homeassistant.components.roku.config_flow.Roku._call",
|
||||
side_effect=SocketGIAError,
|
||||
) as mock_validate_input:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
flow_id=result["flow_id"], user_input={CONF_HOST: HOST}
|
||||
flow_id=result["flow_id"], user_input=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
@@ -186,11 +171,12 @@ async def test_form_unknown_error(hass: HomeAssistantType) -> None:
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_USER}
|
||||
)
|
||||
|
||||
user_input = {CONF_HOST: HOST}
|
||||
with patch(
|
||||
"homeassistant.components.roku.config_flow.Roku._call", side_effect=Exception,
|
||||
) as mock_validate_input:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
flow_id=result["flow_id"], user_input={CONF_HOST: HOST}
|
||||
flow_id=result["flow_id"], user_input=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
@@ -200,36 +186,42 @@ async def test_form_unknown_error(hass: HomeAssistantType) -> None:
|
||||
assert len(mock_validate_input.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import(hass: HomeAssistantType) -> None:
|
||||
async def test_import(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test the import step."""
|
||||
mock_connection(requests_mock)
|
||||
|
||||
user_input = {CONF_HOST: HOST}
|
||||
with patch(
|
||||
"homeassistant.components.roku.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.roku.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await async_init_flow(
|
||||
hass, context={CONF_SOURCE: SOURCE_IMPORT}, data={CONF_HOST: HOST}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=user_input
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
assert result["data"] == {CONF_HOST: HOST}
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_ssdp_discovery(hass: HomeAssistantType) -> None:
|
||||
async def test_ssdp_discovery(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test the ssdp discovery step."""
|
||||
mock_connection(requests_mock)
|
||||
|
||||
discovery_info = {
|
||||
ATTR_SSDP_LOCATION: SSDP_LOCATION,
|
||||
ATTR_UPNP_FRIENDLY_NAME: UPNP_FRIENDLY_NAME,
|
||||
ATTR_UPNP_SERIAL: UPNP_SERIAL,
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={CONF_SOURCE: SOURCE_SSDP},
|
||||
data={
|
||||
ATTR_SSDP_LOCATION: SSDP_LOCATION,
|
||||
ATTR_UPNP_FRIENDLY_NAME: UPNP_FRIENDLY_NAME,
|
||||
ATTR_UPNP_SERIAL: UPNP_SERIAL,
|
||||
},
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_SSDP}, data=discovery_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
@@ -241,14 +233,17 @@ async def test_ssdp_discovery(hass: HomeAssistantType) -> None:
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.roku.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await async_configure_flow(hass, result["flow_id"], {})
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
flow_id=result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == UPNP_FRIENDLY_NAME
|
||||
assert result["data"] == {
|
||||
CONF_HOST: HOST,
|
||||
CONF_NAME: UPNP_FRIENDLY_NAME,
|
||||
}
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
assert result["data"][CONF_NAME] == UPNP_FRIENDLY_NAME
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
@@ -3,6 +3,7 @@ from socket import gaierror as SocketGIAError
|
||||
|
||||
from asynctest import patch
|
||||
from requests.exceptions import RequestException
|
||||
from requests_mock import Mocker
|
||||
from roku import RokuException
|
||||
|
||||
from homeassistant.components.roku.const import DOMAIN
|
||||
@@ -13,50 +14,56 @@ from homeassistant.config_entries import (
|
||||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from tests.components.roku import MockDeviceInfo, setup_integration
|
||||
from tests.components.roku import setup_integration
|
||||
|
||||
|
||||
async def test_config_entry_not_ready(hass: HomeAssistantType) -> None:
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistantType, requests_mock: Mocker
|
||||
) -> None:
|
||||
"""Test the Roku configuration entry not ready."""
|
||||
with patch(
|
||||
"homeassistant.components.roku.Roku._call", side_effect=RokuException,
|
||||
):
|
||||
entry = await setup_integration(hass)
|
||||
entry = await setup_integration(hass, requests_mock)
|
||||
|
||||
assert entry.state == ENTRY_STATE_SETUP_RETRY
|
||||
|
||||
|
||||
async def test_config_entry_not_ready_request(hass: HomeAssistantType) -> None:
|
||||
async def test_config_entry_not_ready_request(
|
||||
hass: HomeAssistantType, requests_mock: Mocker
|
||||
) -> None:
|
||||
"""Test the Roku configuration entry not ready."""
|
||||
with patch(
|
||||
"homeassistant.components.roku.Roku._call", side_effect=RequestException,
|
||||
):
|
||||
entry = await setup_integration(hass)
|
||||
entry = await setup_integration(hass, requests_mock)
|
||||
|
||||
assert entry.state == ENTRY_STATE_SETUP_RETRY
|
||||
|
||||
|
||||
async def test_config_entry_not_ready_socket(hass: HomeAssistantType) -> None:
|
||||
async def test_config_entry_not_ready_socket(
|
||||
hass: HomeAssistantType, requests_mock: Mocker
|
||||
) -> None:
|
||||
"""Test the Roku configuration entry not ready."""
|
||||
with patch(
|
||||
"homeassistant.components.roku.Roku._call", side_effect=SocketGIAError,
|
||||
):
|
||||
entry = await setup_integration(hass)
|
||||
entry = await setup_integration(hass, requests_mock)
|
||||
|
||||
assert entry.state == ENTRY_STATE_SETUP_RETRY
|
||||
|
||||
|
||||
async def test_unload_config_entry(hass: HomeAssistantType) -> None:
|
||||
async def test_unload_config_entry(
|
||||
hass: HomeAssistantType, requests_mock: Mocker
|
||||
) -> None:
|
||||
"""Test the Roku configuration entry unloading."""
|
||||
with patch(
|
||||
"homeassistant.components.roku.Roku.device_info", return_value=MockDeviceInfo,
|
||||
), patch(
|
||||
"homeassistant.components.roku.media_player.async_setup_entry",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.roku.remote.async_setup_entry", return_value=True,
|
||||
):
|
||||
entry = await setup_integration(hass)
|
||||
entry = await setup_integration(hass, requests_mock)
|
||||
|
||||
assert hass.data[DOMAIN][entry.entry_id]
|
||||
assert entry.state == ENTRY_STATE_LOADED
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
"""Tests for the Roku Media Player platform."""
|
||||
from asynctest import patch
|
||||
from requests_mock import Mocker
|
||||
|
||||
from homeassistant.components.media_player.const import (
|
||||
ATTR_INPUT_SOURCE,
|
||||
ATTR_MEDIA_CONTENT_ID,
|
||||
ATTR_MEDIA_CONTENT_TYPE,
|
||||
ATTR_MEDIA_VOLUME_MUTED,
|
||||
DOMAIN as MP_DOMAIN,
|
||||
MEDIA_TYPE_CHANNEL,
|
||||
MEDIA_TYPE_MOVIE,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PLAY,
|
||||
SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_PREVIOUS_TRACK,
|
||||
SUPPORT_SELECT_SOURCE,
|
||||
SUPPORT_TURN_OFF,
|
||||
SUPPORT_TURN_ON,
|
||||
SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_VOLUME_SET,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_MEDIA_NEXT_TRACK,
|
||||
SERVICE_MEDIA_PREVIOUS_TRACK,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
SERVICE_VOLUME_DOWN,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
SERVICE_VOLUME_UP,
|
||||
STATE_PLAYING,
|
||||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from tests.components.roku import UPNP_SERIAL, setup_integration
|
||||
|
||||
MAIN_ENTITY_ID = f"{MP_DOMAIN}.my_roku_3"
|
||||
TV_ENTITY_ID = f"{MP_DOMAIN}.58_onn_roku_tv"
|
||||
|
||||
TV_HOST = "192.168.1.161"
|
||||
TV_SERIAL = "YN00H5555555"
|
||||
|
||||
|
||||
async def test_setup(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test setup with basic config."""
|
||||
await setup_integration(hass, requests_mock)
|
||||
await setup_integration(
|
||||
hass,
|
||||
requests_mock,
|
||||
device="rokutv",
|
||||
app="tvinput-dtv",
|
||||
host=TV_HOST,
|
||||
unique_id=TV_SERIAL,
|
||||
)
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
main = entity_registry.async_get(MAIN_ENTITY_ID)
|
||||
assert hass.states.get(MAIN_ENTITY_ID)
|
||||
assert main.unique_id == UPNP_SERIAL
|
||||
|
||||
tv = entity_registry.async_get(TV_ENTITY_ID)
|
||||
assert hass.states.get(TV_ENTITY_ID)
|
||||
assert tv.unique_id == TV_SERIAL
|
||||
|
||||
|
||||
async def test_supported_features(
|
||||
hass: HomeAssistantType, requests_mock: Mocker
|
||||
) -> None:
|
||||
"""Test supported features."""
|
||||
await setup_integration(hass, requests_mock)
|
||||
|
||||
# Features supported for Rokus
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
assert (
|
||||
SUPPORT_PREVIOUS_TRACK
|
||||
| SUPPORT_NEXT_TRACK
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
| SUPPORT_SELECT_SOURCE
|
||||
| SUPPORT_PLAY
|
||||
| SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_TURN_ON
|
||||
| SUPPORT_TURN_OFF
|
||||
== state.attributes.get("supported_features")
|
||||
)
|
||||
|
||||
|
||||
async def test_tv_supported_features(
|
||||
hass: HomeAssistantType, requests_mock: Mocker
|
||||
) -> None:
|
||||
"""Test supported features for Roku TV."""
|
||||
await setup_integration(
|
||||
hass,
|
||||
requests_mock,
|
||||
device="rokutv",
|
||||
app="tvinput-dtv",
|
||||
host=TV_HOST,
|
||||
unique_id=TV_SERIAL,
|
||||
)
|
||||
|
||||
state = hass.states.get(TV_ENTITY_ID)
|
||||
assert (
|
||||
SUPPORT_PREVIOUS_TRACK
|
||||
| SUPPORT_NEXT_TRACK
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
| SUPPORT_SELECT_SOURCE
|
||||
| SUPPORT_PLAY
|
||||
| SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_TURN_ON
|
||||
| SUPPORT_TURN_OFF
|
||||
== state.attributes.get("supported_features")
|
||||
)
|
||||
|
||||
|
||||
async def test_attributes(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test attributes."""
|
||||
await setup_integration(hass, requests_mock)
|
||||
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
assert state.state == "home"
|
||||
|
||||
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) is None
|
||||
assert state.attributes.get(ATTR_INPUT_SOURCE) == "Roku"
|
||||
|
||||
|
||||
async def test_tv_attributes(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test attributes for Roku TV."""
|
||||
await setup_integration(
|
||||
hass,
|
||||
requests_mock,
|
||||
device="rokutv",
|
||||
app="tvinput-dtv",
|
||||
host=TV_HOST,
|
||||
unique_id=TV_SERIAL,
|
||||
)
|
||||
|
||||
state = hass.states.get(TV_ENTITY_ID)
|
||||
assert state.state == STATE_PLAYING
|
||||
|
||||
assert state.attributes.get(ATTR_MEDIA_CONTENT_TYPE) == MEDIA_TYPE_MOVIE
|
||||
assert state.attributes.get(ATTR_INPUT_SOURCE) == "Antenna TV"
|
||||
|
||||
|
||||
async def test_services(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test the different media player services."""
|
||||
await setup_integration(hass, requests_mock)
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: MAIN_ENTITY_ID}, blocking=True
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/PowerOff")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: MAIN_ENTITY_ID}, blocking=True
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/PowerOn")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_MEDIA_NEXT_TRACK,
|
||||
{ATTR_ENTITY_ID: MAIN_ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/Fwd")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_MEDIA_PREVIOUS_TRACK,
|
||||
{ATTR_ENTITY_ID: MAIN_ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/Rev")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
{ATTR_ENTITY_ID: MAIN_ENTITY_ID, ATTR_INPUT_SOURCE: "Home"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/Home")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
{ATTR_ENTITY_ID: MAIN_ENTITY_ID, ATTR_INPUT_SOURCE: "Netflix"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/launch/12", params={"contentID": "12"})
|
||||
|
||||
|
||||
async def test_tv_services(hass: HomeAssistantType, requests_mock: Mocker) -> None:
|
||||
"""Test the media player services related to Roku TV."""
|
||||
await setup_integration(
|
||||
hass,
|
||||
requests_mock,
|
||||
device="rokutv",
|
||||
app="tvinput-dtv",
|
||||
host=TV_HOST,
|
||||
unique_id=TV_SERIAL,
|
||||
)
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: TV_ENTITY_ID}, blocking=True
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/VolumeUp")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_DOWN,
|
||||
{ATTR_ENTITY_ID: TV_ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/VolumeDown")
|
||||
|
||||
with patch("roku.Roku._post") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
{ATTR_ENTITY_ID: TV_ENTITY_ID, ATTR_MEDIA_VOLUME_MUTED: True},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
remote_mock.assert_called_once_with("/keypress/VolumeMute")
|
||||
|
||||
with patch("roku.Roku.launch") as tune_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
{
|
||||
ATTR_ENTITY_ID: TV_ENTITY_ID,
|
||||
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_CHANNEL,
|
||||
ATTR_MEDIA_CONTENT_ID: "55",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
tune_mock.assert_called_once()
|
||||
Reference in new issue
Block a user