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:
parent
51b2d0b4f8
commit
7a6b13cb0d
10 changed files with 46 additions and 27 deletions
|
@ -17,6 +17,7 @@ from homeassistant.const import (
|
||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from . import validate_auth
|
from . import validate_auth
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -30,8 +31,8 @@ from .const import (
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _get_config_flow_schema(input_dict: Dict[str, Any] = None) -> vol.Schema:
|
def _get_config_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."""
|
"""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:
|
if input_dict is None:
|
||||||
input_dict = {}
|
input_dict = {}
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
# Store current values in case setup fails and user needs to edit
|
# 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
|
# Check if new config entry matches any existing config entries
|
||||||
for entry in self.hass.config_entries.async_entries(DOMAIN):
|
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[CONF_HOST],
|
||||||
user_input.get(CONF_ACCESS_TOKEN),
|
user_input.get(CONF_ACCESS_TOKEN),
|
||||||
user_input[CONF_DEVICE_CLASS],
|
user_input[CONF_DEVICE_CLASS],
|
||||||
|
session=async_get_clientsession(self.hass, False),
|
||||||
):
|
):
|
||||||
errors["base"] = "cant_connect"
|
errors["base"] = "cant_connect"
|
||||||
except vol.Invalid:
|
except vol.Invalid:
|
||||||
|
@ -148,6 +150,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
user_input[CONF_HOST],
|
user_input[CONF_HOST],
|
||||||
user_input.get(CONF_ACCESS_TOKEN),
|
user_input.get(CONF_ACCESS_TOKEN),
|
||||||
user_input[CONF_DEVICE_CLASS],
|
user_input[CONF_DEVICE_CLASS],
|
||||||
|
session=async_get_clientsession(self.hass, False),
|
||||||
)
|
)
|
||||||
|
|
||||||
if await self.async_set_unique_id(
|
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
|
# 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)
|
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"domain": "vizio",
|
"domain": "vizio",
|
||||||
"name": "Vizio SmartCast TV",
|
"name": "Vizio SmartCast",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/vizio",
|
"documentation": "https://www.home-assistant.io/integrations/vizio",
|
||||||
"requirements": ["pyvizio==0.1.21"],
|
"requirements": ["pyvizio==0.1.26"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@raman325"],
|
"codeowners": ["@raman325"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
|
|
|
@ -71,7 +71,7 @@ async def async_setup_entry(
|
||||||
timeout=DEFAULT_TIMEOUT,
|
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)
|
_LOGGER.warning("Failed to connect to %s", host)
|
||||||
raise PlatformNotReady
|
raise PlatformNotReady
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class VizioDevice(MediaPlayerDevice):
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Retrieve latest state of the device."""
|
"""Retrieve latest state of the device."""
|
||||||
if not self._model:
|
if not self._model:
|
||||||
self._model = await self._device.get_model()
|
self._model = await self._device.get_model_name()
|
||||||
|
|
||||||
if not self._sw_version:
|
if not self._sw_version:
|
||||||
self._sw_version = await self._device.get_version()
|
self._sw_version = await self._device.get_version()
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"title": "Vizio SmartCast",
|
"title": "Vizio SmartCast",
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Setup Vizio SmartCast Client",
|
"title": "Setup Vizio SmartCast Device",
|
||||||
"data": {
|
"data": {
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"host": "<Host/IP>:<Port>",
|
"host": "<Host/IP>:<Port>",
|
||||||
|
|
|
@ -1698,7 +1698,7 @@ pyversasense==0.0.6
|
||||||
pyvesync==1.1.0
|
pyvesync==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.vizio
|
# homeassistant.components.vizio
|
||||||
pyvizio==0.1.21
|
pyvizio==0.1.26
|
||||||
|
|
||||||
# homeassistant.components.velux
|
# homeassistant.components.velux
|
||||||
pyvlx==0.2.12
|
pyvlx==0.2.12
|
||||||
|
|
|
@ -596,7 +596,7 @@ pyvera==0.3.7
|
||||||
pyvesync==1.1.0
|
pyvesync==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.vizio
|
# homeassistant.components.vizio
|
||||||
pyvizio==0.1.21
|
pyvizio==0.1.26
|
||||||
|
|
||||||
# homeassistant.components.html5
|
# homeassistant.components.html5
|
||||||
pywebpush==1.9.2
|
pywebpush==1.9.2
|
||||||
|
|
|
@ -53,7 +53,7 @@ def vizio_bypass_setup_fixture():
|
||||||
def vizio_bypass_update_fixture():
|
def vizio_bypass_update_fixture():
|
||||||
"""Mock component update."""
|
"""Mock component update."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
|
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
), patch("homeassistant.components.vizio.media_player.VizioDevice.async_update"):
|
), patch("homeassistant.components.vizio.media_player.VizioDevice.async_update"):
|
||||||
yield
|
yield
|
||||||
|
@ -71,7 +71,7 @@ def vizio_guess_device_type_fixture():
|
||||||
|
|
||||||
@pytest.fixture(name="vizio_cant_connect")
|
@pytest.fixture(name="vizio_cant_connect")
|
||||||
def vizio_cant_connect_fixture():
|
def vizio_cant_connect_fixture():
|
||||||
"""Mock vizio device can't connect."""
|
"""Mock vizio device can't connect with valid auth."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
|
"homeassistant.components.vizio.config_flow.VizioAsync.validate_ha_config",
|
||||||
return_value=False,
|
return_value=False,
|
||||||
|
@ -83,7 +83,7 @@ def vizio_cant_connect_fixture():
|
||||||
def vizio_update_fixture():
|
def vizio_update_fixture():
|
||||||
"""Mock valid updates to vizio device."""
|
"""Mock valid updates to vizio device."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
|
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.get_current_volume",
|
"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",
|
"homeassistant.components.vizio.media_player.VizioAsync.get_power_state",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.get_model",
|
"homeassistant.components.vizio.media_player.VizioAsync.get_model_name",
|
||||||
return_value=MODEL,
|
return_value=MODEL,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.get_version",
|
"homeassistant.components.vizio.media_player.VizioAsync.get_version",
|
||||||
|
|
|
@ -48,7 +48,7 @@ MOCK_IMPORT_VALID_TV_CONFIG = {
|
||||||
CONF_VOLUME_STEP: VOLUME_STEP,
|
CONF_VOLUME_STEP: VOLUME_STEP,
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_INVALID_TV_CONFIG = {
|
MOCK_TV_CONFIG_NO_TOKEN = {
|
||||||
CONF_NAME: NAME,
|
CONF_NAME: NAME,
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
|
CONF_DEVICE_CLASS: DEVICE_CLASS_TV,
|
||||||
|
|
|
@ -25,8 +25,8 @@ from .const import (
|
||||||
HOST,
|
HOST,
|
||||||
HOST2,
|
HOST2,
|
||||||
MOCK_IMPORT_VALID_TV_CONFIG,
|
MOCK_IMPORT_VALID_TV_CONFIG,
|
||||||
MOCK_INVALID_TV_CONFIG,
|
|
||||||
MOCK_SPEAKER_CONFIG,
|
MOCK_SPEAKER_CONFIG,
|
||||||
|
MOCK_TV_CONFIG_NO_TOKEN,
|
||||||
MOCK_USER_VALID_TV_CONFIG,
|
MOCK_USER_VALID_TV_CONFIG,
|
||||||
MOCK_ZEROCONF_SERVICE_INFO,
|
MOCK_ZEROCONF_SERVICE_INFO,
|
||||||
NAME,
|
NAME,
|
||||||
|
@ -219,7 +219,7 @@ async def test_user_error_on_tv_needs_token(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test when config fails custom validation for non null access token when device_class = tv during user setup."""
|
"""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(
|
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
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
|
|
|
@ -97,7 +97,7 @@ async def _test_setup(
|
||||||
async def _test_setup_failure(hass: HomeAssistantType, config: str) -> None:
|
async def _test_setup_failure(hass: HomeAssistantType, config: str) -> None:
|
||||||
"""Test generic Vizio entity setup failure."""
|
"""Test generic Vizio entity setup failure."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.vizio.media_player.VizioAsync.can_connect",
|
"homeassistant.components.vizio.media_player.VizioAsync.can_connect_with_auth_check",
|
||||||
return_value=False,
|
return_value=False,
|
||||||
):
|
):
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data=config, unique_id=UNIQUE_ID)
|
config_entry = MockConfigEntry(domain=DOMAIN, data=config, unique_id=UNIQUE_ID)
|
||||||
|
@ -133,42 +133,54 @@ async def _test_service(
|
||||||
|
|
||||||
|
|
||||||
async def test_speaker_on(
|
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:
|
) -> None:
|
||||||
"""Test Vizio Speaker entity setup when on."""
|
"""Test Vizio Speaker entity setup when on."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_SPEAKER, True)
|
await _test_setup(hass, DEVICE_CLASS_SPEAKER, True)
|
||||||
|
|
||||||
|
|
||||||
async def test_speaker_off(
|
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:
|
) -> None:
|
||||||
"""Test Vizio Speaker entity setup when off."""
|
"""Test Vizio Speaker entity setup when off."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_SPEAKER, False)
|
await _test_setup(hass, DEVICE_CLASS_SPEAKER, False)
|
||||||
|
|
||||||
|
|
||||||
async def test_speaker_unavailable(
|
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:
|
) -> None:
|
||||||
"""Test Vizio Speaker entity setup when unavailable."""
|
"""Test Vizio Speaker entity setup when unavailable."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_SPEAKER, None)
|
await _test_setup(hass, DEVICE_CLASS_SPEAKER, None)
|
||||||
|
|
||||||
|
|
||||||
async def test_init_tv_on(
|
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:
|
) -> None:
|
||||||
"""Test Vizio TV entity setup when on."""
|
"""Test Vizio TV entity setup when on."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_TV, True)
|
await _test_setup(hass, DEVICE_CLASS_TV, True)
|
||||||
|
|
||||||
|
|
||||||
async def test_init_tv_off(
|
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:
|
) -> None:
|
||||||
"""Test Vizio TV entity setup when off."""
|
"""Test Vizio TV entity setup when off."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_TV, False)
|
await _test_setup(hass, DEVICE_CLASS_TV, False)
|
||||||
|
|
||||||
|
|
||||||
async def test_init_tv_unavailable(
|
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:
|
) -> None:
|
||||||
"""Test Vizio TV entity setup when unavailable."""
|
"""Test Vizio TV entity setup when unavailable."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_TV, None)
|
await _test_setup(hass, DEVICE_CLASS_TV, None)
|
||||||
|
@ -189,7 +201,9 @@ async def test_setup_failure_tv(
|
||||||
|
|
||||||
|
|
||||||
async def test_services(
|
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:
|
) -> None:
|
||||||
"""Test all Vizio media player entity services."""
|
"""Test all Vizio media player entity services."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_TV, True)
|
await _test_setup(hass, DEVICE_CLASS_TV, True)
|
||||||
|
@ -218,7 +232,9 @@ async def test_services(
|
||||||
|
|
||||||
|
|
||||||
async def test_options_update(
|
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:
|
) -> None:
|
||||||
"""Test when config entry update event fires."""
|
"""Test when config entry update event fires."""
|
||||||
await _test_setup(hass, DEVICE_CLASS_SPEAKER, True)
|
await _test_setup(hass, DEVICE_CLASS_SPEAKER, True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue