* migrate webostv to new aiopylgtv version of the library and add support for generic commands, input/button commands, and callback state updates * update requirements * cleanup and bump aiopylgtv version * update webostv unit tests * make webostv unit tests work with python 3.7 * cleanup for code checks * cleanup and code review * make all client request functions coroutines * make host required for webostv configuration * remove generic command and button functionality plus related cleanup * fix previous track function * update unit tests * fix imports for unit tests * update unit test * further unit test updates * remove unnecessary setup call in unit tests * restore previous behaviour with client key config file in hass configuration directory
78 lines
2.0 KiB
Python
78 lines
2.0 KiB
Python
"""The tests for the LG webOS media player platform."""
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components import media_player
|
|
from homeassistant.components.media_player.const import (
|
|
ATTR_INPUT_SOURCE,
|
|
ATTR_MEDIA_VOLUME_MUTED,
|
|
SERVICE_SELECT_SOURCE,
|
|
)
|
|
from homeassistant.components.webostv import DOMAIN
|
|
from homeassistant.const import (
|
|
ATTR_ENTITY_ID,
|
|
CONF_HOST,
|
|
CONF_NAME,
|
|
SERVICE_VOLUME_MUTE,
|
|
)
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
if sys.version_info >= (3, 8, 0):
|
|
from unittest.mock import patch
|
|
else:
|
|
from asynctest import patch
|
|
|
|
|
|
NAME = "fake"
|
|
ENTITY_ID = f"{media_player.DOMAIN}.{NAME}"
|
|
|
|
|
|
@pytest.fixture(name="client")
|
|
def client_fixture():
|
|
"""Patch of client library for tests."""
|
|
with patch(
|
|
"homeassistant.components.webostv.WebOsClient", autospec=True
|
|
) as mock_client_class:
|
|
yield mock_client_class.return_value
|
|
|
|
|
|
async def setup_webostv(hass):
|
|
"""Initialize webostv and media_player for tests."""
|
|
assert await async_setup_component(
|
|
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake", CONF_NAME: NAME}},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
async def test_mute(hass, client):
|
|
"""Test simple service call."""
|
|
|
|
await setup_webostv(hass)
|
|
|
|
data = {
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
ATTR_MEDIA_VOLUME_MUTED: True,
|
|
}
|
|
await hass.services.async_call(media_player.DOMAIN, SERVICE_VOLUME_MUTE, data)
|
|
await hass.async_block_till_done()
|
|
|
|
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",
|
|
}
|
|
await hass.services.async_call(media_player.DOMAIN, SERVICE_SELECT_SOURCE, data)
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.is_state(ENTITY_ID, "playing")
|
|
client.launch_app.assert_not_called()
|
|
client.set_input.assert_not_called()
|