* add media player test and update media player logic to qualify vizio for platinum quality score * add SCAN_INTERVAL and log message once when device goes from available to unavailable and vice versa * move test constants into one file to avoid defining dupes in each test file * move constant to shrink diff * move pytest fixtures to conftest.py * remove commented out code * move unload test to test_init * updates to tests and logging based on review * bypass notification service * add fixture so component setup makes it through config flow * split failure tests into two * fix setup and entity check for test_init and setup failures in test_media_player * make domain references consistent across test files * remove logging steps that were introduced to help debug * move common patches out to new fixture and use config entry everywhere appropriate * fix docstring * add test for update options to increase code coverage * add one more assert * refactor test_media_player to move boiler plate logic out of each test into _test_init function * final refactor of test_media_player to move repeat logic into separate function * update docstrings * refactor setup failure tests to move shared logic into private function * fix last new functions code to use variable instead of static config variable * remove trailing comma * test that volume_step gets properly passed to Vizio volume function * fix comment language * assert with unittest.mock.call in _test_service and use config_entries.async_setup instead of config_entries.async_add * replace config_entries.async_add with config_entries.async_setup everywhere * simplify if statement for argument assertion * fix logging based on style guide * remove accidentally committed changes * update scan interval to something more reasonable and add tests for availability changes * change filter function to list comprehension, simplify log messages, remove default entity id from logs since it is user configurable, fix docstrings
102 lines
3.1 KiB
Python
102 lines
3.1 KiB
Python
"""Configure py.test."""
|
|
from asynctest import patch
|
|
import pytest
|
|
from pyvizio.const import DEVICE_CLASS_SPEAKER
|
|
from pyvizio.vizio import MAX_VOLUME
|
|
|
|
from .const import CURRENT_INPUT, INPUT_LIST, UNIQUE_ID
|
|
|
|
|
|
class MockInput:
|
|
"""Mock Vizio device input."""
|
|
|
|
def __init__(self, name):
|
|
"""Initialize mock Vizio device input."""
|
|
self.meta_name = name
|
|
self.name = name
|
|
|
|
|
|
def get_mock_inputs(input_list):
|
|
"""Return list of MockInput."""
|
|
return [MockInput(input) for input in input_list]
|
|
|
|
|
|
@pytest.fixture(name="skip_notifications", autouse=True)
|
|
def skip_notifications_fixture():
|
|
"""Skip notification calls."""
|
|
with patch("homeassistant.components.persistent_notification.async_create"), patch(
|
|
"homeassistant.components.persistent_notification.async_dismiss"
|
|
):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="vizio_connect")
|
|
def vizio_connect_fixture():
|
|
"""Mock valid vizio device and entry setup."""
|
|
with patch(
|
|
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
|
|
return_value=True,
|
|
), patch(
|
|
"homeassistant.components.vizio.config_flow.VizioAsync.get_unique_id",
|
|
return_value=UNIQUE_ID,
|
|
):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="vizio_bypass_setup")
|
|
def vizio_bypass_setup_fixture():
|
|
"""Mock component setup."""
|
|
with patch("homeassistant.components.vizio.async_setup_entry", return_value=True):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="vizio_bypass_update")
|
|
def vizio_bypass_update_fixture():
|
|
"""Mock component update."""
|
|
with patch(
|
|
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
|
|
return_value=True,
|
|
), patch("homeassistant.components.vizio.media_player.VizioDevice.async_update"):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="vizio_guess_device_type")
|
|
def vizio_guess_device_type_fixture():
|
|
"""Mock vizio async_guess_device_type function."""
|
|
with patch(
|
|
"homeassistant.components.vizio.config_flow.async_guess_device_type",
|
|
return_value="speaker",
|
|
):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="vizio_cant_connect")
|
|
def vizio_cant_connect_fixture():
|
|
"""Mock vizio device cant connect."""
|
|
with patch(
|
|
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
|
|
return_value=False,
|
|
):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="vizio_update")
|
|
def vizio_update_fixture():
|
|
"""Mock valid updates to vizio device."""
|
|
with patch(
|
|
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
|
|
return_value=True,
|
|
), patch(
|
|
"homeassistant.components.vizio.media_player.VizioAsync.get_current_volume",
|
|
return_value=int(MAX_VOLUME[DEVICE_CLASS_SPEAKER] / 2),
|
|
), patch(
|
|
"homeassistant.components.vizio.media_player.VizioAsync.get_current_input",
|
|
return_value=MockInput(CURRENT_INPUT),
|
|
), patch(
|
|
"homeassistant.components.vizio.media_player.VizioAsync.get_inputs",
|
|
return_value=get_mock_inputs(INPUT_LIST),
|
|
), patch(
|
|
"homeassistant.components.vizio.media_player.VizioAsync.get_power_state",
|
|
return_value=True,
|
|
):
|
|
yield
|