diff --git a/homeassistant/components/vizio/manifest.json b/homeassistant/components/vizio/manifest.json index 7f397a4ed0c..6a5b9c33111 100644 --- a/homeassistant/components/vizio/manifest.json +++ b/homeassistant/components/vizio/manifest.json @@ -2,7 +2,7 @@ "domain": "vizio", "name": "Vizio SmartCast TV", "documentation": "https://www.home-assistant.io/integrations/vizio", - "requirements": ["pyvizio==0.1.16"], + "requirements": ["pyvizio==0.1.19"], "dependencies": [], "codeowners": ["@raman325"], "config_flow": true, diff --git a/homeassistant/components/vizio/media_player.py b/homeassistant/components/vizio/media_player.py index 439a9a972d4..349373017da 100644 --- a/homeassistant/components/vizio/media_player.py +++ b/homeassistant/components/vizio/media_player.py @@ -107,9 +107,17 @@ class VizioDevice(MediaPlayerDevice): self._max_volume = float(self._device.get_max_volume()) self._icon = ICON[device_class] self._available = True + self._model = None + self._sw_version = None async def async_update(self) -> None: """Retrieve latest state of the device.""" + if not self._model: + self._model = await self._device.get_model() + + if not self._sw_version: + self._sw_version = await self._device.get_version() + is_on = await self._device.get_power_state(log_api_exception=False) if is_on is None: @@ -141,9 +149,9 @@ class VizioDevice(MediaPlayerDevice): input_ = await self._device.get_current_input(log_api_exception=False) if input_ is not None: - self._current_input = input_.meta_name + self._current_input = input_ - inputs = await self._device.get_inputs(log_api_exception=False) + inputs = await self._device.get_inputs_list(log_api_exception=False) if inputs is not None: self._available_inputs = [input_.name for input_ in inputs] @@ -235,6 +243,8 @@ class VizioDevice(MediaPlayerDevice): "identifiers": {(DOMAIN, self._config_entry.unique_id)}, "name": self.name, "manufacturer": "VIZIO", + "model": self._model, + "sw_version": self._sw_version, } @property @@ -267,7 +277,7 @@ class VizioDevice(MediaPlayerDevice): async def async_select_source(self, source: str) -> None: """Select input source.""" - await self._device.input_switch(source) + await self._device.set_input(source) async def async_volume_up(self) -> None: """Increase volume of the device.""" diff --git a/requirements_all.txt b/requirements_all.txt index aaeda0753ce..92391040774 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1693,7 +1693,7 @@ pyversasense==0.0.6 pyvesync==1.1.0 # homeassistant.components.vizio -pyvizio==0.1.16 +pyvizio==0.1.19 # homeassistant.components.velux pyvlx==0.2.12 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 92d85b3e5d8..4f0e6a21a2a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -570,7 +570,7 @@ pyvera==0.3.7 pyvesync==1.1.0 # homeassistant.components.vizio -pyvizio==0.1.16 +pyvizio==0.1.19 # homeassistant.components.html5 pywebpush==1.9.2 diff --git a/tests/components/vizio/conftest.py b/tests/components/vizio/conftest.py index f427e6d3e5a..581ea7cdd5c 100644 --- a/tests/components/vizio/conftest.py +++ b/tests/components/vizio/conftest.py @@ -1,10 +1,9 @@ """Configure py.test.""" from asynctest import patch import pytest -from pyvizio.const import DEVICE_CLASS_SPEAKER -from pyvizio.vizio import MAX_VOLUME +from pyvizio.const import DEVICE_CLASS_SPEAKER, MAX_VOLUME -from .const import CURRENT_INPUT, INPUT_LIST, UNIQUE_ID +from .const import CURRENT_INPUT, INPUT_LIST, MODEL, UNIQUE_ID, VERSION class MockInput: @@ -91,12 +90,18 @@ def vizio_update_fixture(): return_value=int(MAX_VOLUME[DEVICE_CLASS_SPEAKER] / 2), ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_current_input", - return_value=MockInput(CURRENT_INPUT), + return_value=CURRENT_INPUT, ), patch( - "homeassistant.components.vizio.media_player.VizioAsync.get_inputs", + "homeassistant.components.vizio.media_player.VizioAsync.get_inputs_list", return_value=get_mock_inputs(INPUT_LIST), ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_power_state", return_value=True, + ), patch( + "homeassistant.components.vizio.media_player.VizioAsync.get_model", + return_value=MODEL, + ), patch( + "homeassistant.components.vizio.media_player.VizioAsync.get_version", + return_value=VERSION, ): yield diff --git a/tests/components/vizio/const.py b/tests/components/vizio/const.py index dd6ecda55d0..537db445a85 100644 --- a/tests/components/vizio/const.py +++ b/tests/components/vizio/const.py @@ -26,6 +26,8 @@ HOST2 = "192.168.1.2:9000" ACCESS_TOKEN = "deadbeef" VOLUME_STEP = 2 UNIQUE_ID = "testid" +MODEL = "model" +VERSION = "version" MOCK_USER_VALID_TV_CONFIG = { CONF_NAME: NAME, diff --git a/tests/components/vizio/test_media_player.py b/tests/components/vizio/test_media_player.py index d87b86f8642..bbbbca8c359 100644 --- a/tests/components/vizio/test_media_player.py +++ b/tests/components/vizio/test_media_player.py @@ -7,8 +7,8 @@ import pytest from pyvizio.const import ( DEVICE_CLASS_SPEAKER as VIZIO_DEVICE_CLASS_SPEAKER, DEVICE_CLASS_TV as VIZIO_DEVICE_CLASS_TV, + MAX_VOLUME, ) -from pyvizio.vizio import MAX_VOLUME from homeassistant.components.media_player import ( ATTR_INPUT_SOURCE, @@ -111,7 +111,7 @@ async def _test_service( hass: HomeAssistantType, vizio_func_name: str, ha_service_name: str, - additional_service_data: dict = None, + additional_service_data: dict, *args, **kwargs, ) -> None: @@ -194,8 +194,8 @@ async def test_services( """Test all Vizio media player entity services.""" await _test_setup(hass, DEVICE_CLASS_TV, True) - await _test_service(hass, "pow_on", SERVICE_TURN_ON) - await _test_service(hass, "pow_off", SERVICE_TURN_OFF) + await _test_service(hass, "pow_on", SERVICE_TURN_ON, None) + await _test_service(hass, "pow_off", SERVICE_TURN_OFF, None) await _test_service( hass, "mute_on", SERVICE_VOLUME_MUTE, {ATTR_MEDIA_VOLUME_MUTED: True} ) @@ -203,18 +203,18 @@ async def test_services( hass, "mute_off", SERVICE_VOLUME_MUTE, {ATTR_MEDIA_VOLUME_MUTED: False} ) await _test_service( - hass, "input_switch", SERVICE_SELECT_SOURCE, {ATTR_INPUT_SOURCE: "USB"}, "USB" + hass, "set_input", SERVICE_SELECT_SOURCE, {ATTR_INPUT_SOURCE: "USB"}, "USB" ) - await _test_service(hass, "vol_up", SERVICE_VOLUME_UP) - await _test_service(hass, "vol_down", SERVICE_VOLUME_DOWN) + await _test_service(hass, "vol_up", SERVICE_VOLUME_UP, None) + await _test_service(hass, "vol_down", SERVICE_VOLUME_DOWN, None) await _test_service( hass, "vol_up", SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 1} ) await _test_service( hass, "vol_down", SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 0} ) - await _test_service(hass, "ch_up", SERVICE_MEDIA_NEXT_TRACK) - await _test_service(hass, "ch_down", SERVICE_MEDIA_PREVIOUS_TRACK) + await _test_service(hass, "ch_up", SERVICE_MEDIA_NEXT_TRACK, None) + await _test_service(hass, "ch_down", SERVICE_MEDIA_PREVIOUS_TRACK, None) async def test_options_update( @@ -231,7 +231,7 @@ async def test_options_update( entry=config_entry, options=new_options, ) assert config_entry.options == updated_options - await _test_service(hass, "vol_up", SERVICE_VOLUME_UP, num=VOLUME_STEP) + await _test_service(hass, "vol_up", SERVICE_VOLUME_UP, None, num=VOLUME_STEP) async def _test_update_availability_switch(