2017-12-22 12:38:00 -05:00
|
|
|
"""The tests for the LG webOS media player platform."""
|
2022-01-14 23:48:45 +02:00
|
|
|
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
2019-12-31 18:26:35 -05:00
|
|
|
from homeassistant.components.media_player.const import (
|
|
|
|
ATTR_INPUT_SOURCE,
|
|
|
|
ATTR_MEDIA_VOLUME_MUTED,
|
|
|
|
SERVICE_SELECT_SOURCE,
|
|
|
|
)
|
2020-04-14 19:26:13 +01:00
|
|
|
from homeassistant.components.webostv.const import (
|
2020-01-02 16:32:57 -05:00
|
|
|
ATTR_BUTTON,
|
2020-05-27 21:51:39 +08:00
|
|
|
ATTR_PAYLOAD,
|
2020-01-02 16:32:57 -05:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_BUTTON,
|
|
|
|
SERVICE_COMMAND,
|
2019-12-31 18:26:35 -05:00
|
|
|
)
|
2022-01-14 23:48:45 +02:00
|
|
|
from homeassistant.const import ATTR_COMMAND, ATTR_ENTITY_ID, SERVICE_VOLUME_MUTE
|
2017-12-22 12:38:00 -05:00
|
|
|
|
2022-01-14 23:48:45 +02:00
|
|
|
from . import ENTITY_ID, setup_webostv
|
2021-03-18 04:59:48 +01:00
|
|
|
|
|
|
|
|
2019-12-31 18:26:35 -05:00
|
|
|
async def test_mute(hass, client):
|
|
|
|
"""Test simple service call."""
|
|
|
|
await setup_webostv(hass)
|
2017-12-22 12:38:00 -05:00
|
|
|
|
2019-12-31 18:26:35 -05:00
|
|
|
data = {
|
|
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
|
|
ATTR_MEDIA_VOLUME_MUTED: True,
|
|
|
|
}
|
2022-01-14 23:48:45 +02:00
|
|
|
|
|
|
|
assert await hass.services.async_call(MP_DOMAIN, SERVICE_VOLUME_MUTE, data, True)
|
2019-12-31 18:26:35 -05:00
|
|
|
await hass.async_block_till_done()
|
2017-12-22 12:38:00 -05:00
|
|
|
|
2019-12-31 18:26:35 -05:00
|
|
|
client.set_mute.assert_called_once()
|
|
|
|
|
|
|
|
|
|
|
|
async def test_select_source_with_empty_source_list(hass, client):
|
|
|
|
"""Ensure we don't call client methods when we don't have sources."""
|
|
|
|
await setup_webostv(hass)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
|
|
ATTR_INPUT_SOURCE: "nonexistent",
|
|
|
|
}
|
2022-01-14 23:48:45 +02:00
|
|
|
await hass.services.async_call(MP_DOMAIN, SERVICE_SELECT_SOURCE, data)
|
2019-12-31 18:26:35 -05:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
client.launch_app.assert_not_called()
|
|
|
|
client.set_input.assert_not_called()
|
2020-01-02 16:32:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
async def test_button(hass, client):
|
|
|
|
"""Test generic button functionality."""
|
|
|
|
await setup_webostv(hass)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
|
|
ATTR_BUTTON: "test",
|
|
|
|
}
|
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_BUTTON, data)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
client.button.assert_called_once()
|
|
|
|
client.button.assert_called_with("test")
|
|
|
|
|
|
|
|
|
|
|
|
async def test_command(hass, client):
|
2020-05-27 21:51:39 +08:00
|
|
|
"""Test generic command functionality."""
|
|
|
|
await setup_webostv(hass)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
|
|
ATTR_COMMAND: "test",
|
|
|
|
}
|
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_COMMAND, data)
|
|
|
|
await hass.async_block_till_done()
|
2020-01-02 16:32:57 -05:00
|
|
|
|
2020-05-27 21:51:39 +08:00
|
|
|
client.request.assert_called_with("test", payload=None)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_command_with_optional_arg(hass, client):
|
|
|
|
"""Test generic command functionality."""
|
2020-01-02 16:32:57 -05:00
|
|
|
await setup_webostv(hass)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
|
|
ATTR_COMMAND: "test",
|
2020-05-27 21:51:39 +08:00
|
|
|
ATTR_PAYLOAD: {"target": "https://www.google.com"},
|
2020-01-02 16:32:57 -05:00
|
|
|
}
|
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_COMMAND, data)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-05-27 21:51:39 +08:00
|
|
|
client.request.assert_called_with(
|
|
|
|
"test", payload={"target": "https://www.google.com"}
|
|
|
|
)
|