Update vizio dependency and integration name (#31975)

* bump pyvizio version and clean up code

* fix requirements

* update parameter to optional per review in docs PR
This commit is contained in:
Raman Gupta 2020-02-20 11:43:29 -05:00 committed by GitHub
parent 51b2d0b4f8
commit 7a6b13cb0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 46 additions and 27 deletions

View file

@ -17,6 +17,7 @@ from homeassistant.const import (
CONF_TYPE,
)
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from . import validate_auth
from .const import (
@ -30,8 +31,8 @@ from .const import (
_LOGGER = logging.getLogger(__name__)
def _get_config_flow_schema(input_dict: Dict[str, Any] = None) -> vol.Schema:
"""Return schema defaults based on user input/config dict. Retain info already provided for future form views by setting them as defaults in schema."""
def _get_config_schema(input_dict: Dict[str, Any] = None) -> vol.Schema:
"""Return schema defaults for config data based on user input/config dict. Retain info already provided for future form views by setting them as defaults in schema."""
if input_dict is None:
input_dict = {}
@ -109,7 +110,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
if user_input is not None:
# Store current values in case setup fails and user needs to edit
self._user_schema = _get_config_flow_schema(user_input)
self._user_schema = _get_config_schema(user_input)
# Check if new config entry matches any existing config entries
for entry in self.hass.config_entries.async_entries(DOMAIN):
@ -131,6 +132,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
user_input[CONF_HOST],
user_input.get(CONF_ACCESS_TOKEN),
user_input[CONF_DEVICE_CLASS],
session=async_get_clientsession(self.hass, False),
):
errors["base"] = "cant_connect"
except vol.Invalid:
@ -148,6 +150,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
user_input[CONF_HOST],
user_input.get(CONF_ACCESS_TOKEN),
user_input[CONF_DEVICE_CLASS],
session=async_get_clientsession(self.hass, False),
)
if await self.async_set_unique_id(
@ -162,7 +165,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
)
# Use user_input params as default values for schema if user_input is non-empty, otherwise use default schema
schema = self._user_schema or _get_config_flow_schema()
schema = self._user_schema or _get_config_schema()
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)

View file

@ -1,8 +1,8 @@
{
"domain": "vizio",
"name": "Vizio SmartCast TV",
"name": "Vizio SmartCast",
"documentation": "https://www.home-assistant.io/integrations/vizio",
"requirements": ["pyvizio==0.1.21"],
"requirements": ["pyvizio==0.1.26"],
"dependencies": [],
"codeowners": ["@raman325"],
"config_flow": true,

View file

@ -71,7 +71,7 @@ async def async_setup_entry(
timeout=DEFAULT_TIMEOUT,
)
if not await device.can_connect():
if not await device.can_connect_with_auth_check():
_LOGGER.warning("Failed to connect to %s", host)
raise PlatformNotReady
@ -113,7 +113,7 @@ class VizioDevice(MediaPlayerDevice):
async def async_update(self) -> None:
"""Retrieve latest state of the device."""
if not self._model:
self._model = await self._device.get_model()
self._model = await self._device.get_model_name()
if not self._sw_version:
self._sw_version = await self._device.get_version()

View file

@ -3,7 +3,7 @@
"title": "Vizio SmartCast",
"step": {
"user": {
"title": "Setup Vizio SmartCast Client",
"title": "Setup Vizio SmartCast Device",
"data": {
"name": "Name",
"host": "<Host/IP>:<Port>",

View file

@ -1698,7 +1698,7 @@ pyversasense==0.0.6
pyvesync==1.1.0
# homeassistant.components.vizio
pyvizio==0.1.21
pyvizio==0.1.26
# homeassistant.components.velux
pyvlx==0.2.12

View file

@ -596,7 +596,7 @@ pyvera==0.3.7
pyvesync==1.1.0
# homeassistant.components.vizio
pyvizio==0.1.21
pyvizio==0.1.26
# homeassistant.components.html5
pywebpush==1.9.2

View file

@ -53,7 +53,7 @@ def vizio_bypass_setup_fixture():
def vizio_bypass_update_fixture():
"""Mock component update."""
with patch(
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
return_value=True,
), patch("homeassistant.components.vizio.media_player.VizioDevice.async_update"):
yield
@ -71,7 +71,7 @@ def vizio_guess_device_type_fixture():
@pytest.fixture(name="vizio_cant_connect")
def vizio_cant_connect_fixture():
"""Mock vizio device can't connect."""
"""Mock vizio device can't connect with valid auth."""
with patch(
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
return_value=False,
@ -83,7 +83,7 @@ def vizio_cant_connect_fixture():
def vizio_update_fixture():
"""Mock valid updates to vizio device."""
with patch(
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
return_value=True,
), patch(
"homeassistant.components.vizio.media_player.VizioAsync.get_current_volume",
@ -98,7 +98,7 @@ def vizio_update_fixture():
"homeassistant.components.vizio.media_player.VizioAsync.get_power_state",
return_value=True,
), patch(
"homeassistant.components.vizio.media_player.VizioAsync.get_model",
"homeassistant.components.vizio.media_player.VizioAsync.get_model_name",
return_value=MODEL,
), patch(
"homeassistant.components.vizio.media_player.VizioAsync.get_version",

View file

@ -48,7 +48,7 @@ MOCK_IMPORT_VALID_TV_CONFIG = {
CONF_VOLUME_STEP: VOLUME_STEP,
}
MOCK_INVALID_TV_CONFIG = {
MOCK_TV_CONFIG_NO_TOKEN = {
CONF_NAME: NAME,
CONF_HOST: HOST,
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,

View file

@ -25,8 +25,8 @@ from .const import (
HOST,
HOST2,
MOCK_IMPORT_VALID_TV_CONFIG,
MOCK_INVALID_TV_CONFIG,
MOCK_SPEAKER_CONFIG,
MOCK_TV_CONFIG_NO_TOKEN,
MOCK_USER_VALID_TV_CONFIG,
MOCK_ZEROCONF_SERVICE_INFO,
NAME,
@ -219,7 +219,7 @@ async def test_user_error_on_tv_needs_token(
) -> None:
"""Test when config fails custom validation for non null access token when device_class = tv during user setup."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_INVALID_TV_CONFIG
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_TV_CONFIG_NO_TOKEN
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM

View file

@ -97,7 +97,7 @@ async def _test_setup(
async def _test_setup_failure(hass: HomeAssistantType, config: str) -> None:
"""Test generic Vizio entity setup failure."""
with patch(
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
return_value=False,
):
config_entry = MockConfigEntry(domain=DOMAIN, data=config, unique_id=UNIQUE_ID)
@ -133,42 +133,54 @@ async def _test_service(
async def test_speaker_on(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio Speaker entity setup when on."""
await _test_setup(hass, DEVICE_CLASS_SPEAKER, True)
async def test_speaker_off(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio Speaker entity setup when off."""
await _test_setup(hass, DEVICE_CLASS_SPEAKER, False)
async def test_speaker_unavailable(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio Speaker entity setup when unavailable."""
await _test_setup(hass, DEVICE_CLASS_SPEAKER, None)
async def test_init_tv_on(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio TV entity setup when on."""
await _test_setup(hass, DEVICE_CLASS_TV, True)
async def test_init_tv_off(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio TV entity setup when off."""
await _test_setup(hass, DEVICE_CLASS_TV, False)
async def test_init_tv_unavailable(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test Vizio TV entity setup when unavailable."""
await _test_setup(hass, DEVICE_CLASS_TV, None)
@ -189,7 +201,9 @@ async def test_setup_failure_tv(
async def test_services(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test all Vizio media player entity services."""
await _test_setup(hass, DEVICE_CLASS_TV, True)
@ -218,7 +232,9 @@ async def test_services(
async def test_options_update(
hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update: pytest.fixture
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_update: pytest.fixture,
) -> None:
"""Test when config entry update event fires."""
await _test_setup(hass, DEVICE_CLASS_SPEAKER, True)