From 7a6b13cb0dbdb75abe9042d35831c7d6bac64fc6 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 20 Feb 2020 11:43:29 -0500 Subject: [PATCH] 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 --- homeassistant/components/vizio/config_flow.py | 11 +++--- homeassistant/components/vizio/manifest.json | 4 +-- .../components/vizio/media_player.py | 4 +-- homeassistant/components/vizio/strings.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/vizio/conftest.py | 8 ++--- tests/components/vizio/const.py | 2 +- tests/components/vizio/test_config_flow.py | 4 +-- tests/components/vizio/test_media_player.py | 34 ++++++++++++++----- 10 files changed, 46 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index 4fba0f06165..c62222f2d91 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -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) diff --git a/homeassistant/components/vizio/manifest.json b/homeassistant/components/vizio/manifest.json index bf88ed9f437..08d442b803e 100644 --- a/homeassistant/components/vizio/manifest.json +++ b/homeassistant/components/vizio/manifest.json @@ -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, diff --git a/homeassistant/components/vizio/media_player.py b/homeassistant/components/vizio/media_player.py index 349373017da..13554ab8f36 100644 --- a/homeassistant/components/vizio/media_player.py +++ b/homeassistant/components/vizio/media_player.py @@ -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() diff --git a/homeassistant/components/vizio/strings.json b/homeassistant/components/vizio/strings.json index 5a554b7e3db..d1890ee49ed 100644 --- a/homeassistant/components/vizio/strings.json +++ b/homeassistant/components/vizio/strings.json @@ -3,7 +3,7 @@ "title": "Vizio SmartCast", "step": { "user": { - "title": "Setup Vizio SmartCast Client", + "title": "Setup Vizio SmartCast Device", "data": { "name": "Name", "host": ":", diff --git a/requirements_all.txt b/requirements_all.txt index 0149c8781b8..1f16e8db895 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 27f6b0a82dd..ae4d9230afe 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/vizio/conftest.py b/tests/components/vizio/conftest.py index 581ea7cdd5c..c42f03db064 100644 --- a/tests/components/vizio/conftest.py +++ b/tests/components/vizio/conftest.py @@ -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", diff --git a/tests/components/vizio/const.py b/tests/components/vizio/const.py index 537db445a85..c241394737e 100644 --- a/tests/components/vizio/const.py +++ b/tests/components/vizio/const.py @@ -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, diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index 5a24e2d1d69..416617d4b9b 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -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 diff --git a/tests/components/vizio/test_media_player.py b/tests/components/vizio/test_media_player.py index bbbbca8c359..a94effa7433 100644 --- a/tests/components/vizio/test_media_player.py +++ b/tests/components/vizio/test_media_player.py @@ -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)