Update media_player and add tests to qualify vizio integration for platinum quality score (#31187)
* 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
This commit is contained in:
1 parent
9ab6d08b97
commit
73ea34e417
8 files changed
+559
-145
No files matched your search
@@ -1,7 +1,4 @@
|
||||
"""Tests for Vizio config flow."""
|
||||
import logging
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -20,113 +17,26 @@ from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PORT,
|
||||
CONF_TYPE,
|
||||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from .const import (
|
||||
ACCESS_TOKEN,
|
||||
HOST,
|
||||
HOST2,
|
||||
MOCK_IMPORT_VALID_TV_CONFIG,
|
||||
MOCK_INVALID_TV_CONFIG,
|
||||
MOCK_SPEAKER_CONFIG,
|
||||
MOCK_USER_VALID_TV_CONFIG,
|
||||
MOCK_ZEROCONF_SERVICE_INFO,
|
||||
NAME,
|
||||
NAME2,
|
||||
UNIQUE_ID,
|
||||
VOLUME_STEP,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
NAME = "Vizio"
|
||||
NAME2 = "Vizio2"
|
||||
HOST = "192.168.1.1:9000"
|
||||
HOST2 = "192.168.1.2:9000"
|
||||
ACCESS_TOKEN = "deadbeef"
|
||||
VOLUME_STEP = 2
|
||||
UNIQUE_ID = "testid"
|
||||
|
||||
MOCK_USER_VALID_TV_CONFIG = {
|
||||
CONF_NAME: NAME,
|
||||
CONF_HOST: HOST,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
|
||||
CONF_ACCESS_TOKEN: ACCESS_TOKEN,
|
||||
}
|
||||
|
||||
MOCK_IMPORT_VALID_TV_CONFIG = {
|
||||
CONF_NAME: NAME,
|
||||
CONF_HOST: HOST,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
|
||||
CONF_ACCESS_TOKEN: ACCESS_TOKEN,
|
||||
CONF_VOLUME_STEP: VOLUME_STEP,
|
||||
}
|
||||
|
||||
MOCK_INVALID_TV_CONFIG = {
|
||||
CONF_NAME: NAME,
|
||||
CONF_HOST: HOST,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
|
||||
}
|
||||
|
||||
MOCK_SPEAKER_CONFIG = {
|
||||
CONF_NAME: NAME,
|
||||
CONF_HOST: HOST,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_SPEAKER,
|
||||
}
|
||||
|
||||
VIZIO_ZEROCONF_SERVICE_TYPE = "_viziocast._tcp.local."
|
||||
ZEROCONF_NAME = f"{NAME}.{VIZIO_ZEROCONF_SERVICE_TYPE}"
|
||||
ZEROCONF_HOST = HOST.split(":")[0]
|
||||
ZEROCONF_PORT = HOST.split(":")[1]
|
||||
|
||||
MOCK_ZEROCONF_ENTRY = {
|
||||
CONF_TYPE: VIZIO_ZEROCONF_SERVICE_TYPE,
|
||||
CONF_NAME: ZEROCONF_NAME,
|
||||
CONF_HOST: ZEROCONF_HOST,
|
||||
CONF_PORT: ZEROCONF_PORT,
|
||||
"properties": {"name": "SB4031-D5"},
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
|
||||
|
||||
async def test_user_flow_minimum_fields(
|
||||
hass: HomeAssistantType,
|
||||
@@ -142,12 +52,7 @@ async def test_user_flow_minimum_fields(
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_NAME: NAME,
|
||||
CONF_HOST: HOST,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_SPEAKER,
|
||||
},
|
||||
result["flow_id"], user_input=MOCK_SPEAKER_CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
@@ -172,13 +77,7 @@ async def test_user_flow_all_fields(
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_NAME: NAME,
|
||||
CONF_HOST: HOST,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
|
||||
CONF_ACCESS_TOKEN: ACCESS_TOKEN,
|
||||
},
|
||||
result["flow_id"], user_input=MOCK_USER_VALID_TV_CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
@@ -408,7 +307,7 @@ async def test_zeroconf_flow(
|
||||
vizio_guess_device_type: pytest.fixture,
|
||||
) -> None:
|
||||
"""Test zeroconf config flow."""
|
||||
discovery_info = MOCK_ZEROCONF_ENTRY.copy()
|
||||
discovery_info = MOCK_ZEROCONF_SERVICE_INFO.copy()
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info
|
||||
)
|
||||
@@ -444,7 +343,7 @@ async def test_zeroconf_flow_already_configured(
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
# Try rediscovering same device
|
||||
discovery_info = MOCK_ZEROCONF_ENTRY.copy()
|
||||
discovery_info = MOCK_ZEROCONF_SERVICE_INFO.copy()
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user