def vizio_update_with_apps_fixture(vizio_update: pytest.fixture): """Mock valid updates to vizio device that supports apps.""" with patch( "homeassistant.components.vizio.media_player.VizioAsync.get_inputs_list", return_value=get_mock_inputs(INPUT_LIST_WITH_APPS), ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_current_input", return_value="CAST", ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_current_app_config", return_value=AppConfig(**CURRENT_APP_CONFIG), ): yield
def vizio_update_with_apps_on_input_fixture(vizio_update: pytest.fixture): """Mock valid updates to vizio device that supports apps but is on a TV input.""" with patch( "homeassistant.components.vizio.media_player.VizioAsync.get_inputs_list", return_value=get_mock_inputs(INPUT_LIST_WITH_APPS), ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_current_input", return_value=CURRENT_INPUT, ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_current_app_config", return_value=AppConfig("unknown", 1, "app"), ): yield
async def test_setup_with_no_running_app( hass: HomeAssistantType, vizio_connect: pytest.fixture, vizio_update_with_apps: pytest.fixture, caplog: pytest.fixture, ) -> None: """Test device setup with apps where no app is running.""" async with _cm_for_test_setup_tv_with_apps( hass, MOCK_USER_VALID_TV_CONFIG, vars(AppConfig()) ): attr = hass.states.get(ENTITY_ID).attributes _assert_source_list_with_apps(list(INPUT_LIST_WITH_APPS + APP_NAME_LIST), attr) assert attr["source"] == "CAST" assert "app_id" not in attr assert "app_name" not in attr
async def _test_setup_with_apps( hass: HomeAssistantType, device_config: Dict[str, Any], app: Optional[str], app_config: Dict[str, Any], ) -> None: """Test Vizio Device with apps entity setup.""" config_entry = MockConfigEntry( domain=DOMAIN, data=vol.Schema(VIZIO_SCHEMA)(device_config), unique_id=UNIQUE_ID) with patch( "homeassistant.components.vizio.media_player.VizioAsync.get_all_audio_settings", return_value={ "volume": int(MAX_VOLUME[VIZIO_DEVICE_CLASS_TV] / 2), "mute": "Off", }, ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_power_state", return_value=True, ), patch( "homeassistant.components.vizio.media_player.VizioAsync.get_current_app_config", return_value=AppConfig(**app_config), ): config_entry.add_to_hass(hass) assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() attr = hass.states.get(ENTITY_ID).attributes assert attr["friendly_name"] == NAME assert attr["device_class"] == DEVICE_CLASS_TV assert hass.states.get(ENTITY_ID).state == STATE_ON if device_config.get(CONF_APPS, {}).get(CONF_INCLUDE) or device_config.get( CONF_APPS, {}).get(CONF_EXCLUDE): list_to_test = list(INPUT_LIST_WITH_APPS + [CURRENT_APP]) elif device_config.get(CONF_APPS, {}).get(CONF_ADDITIONAL_CONFIGS): list_to_test = list(INPUT_LIST_WITH_APPS + APP_LIST + [ app["name"] for app in device_config[CONF_APPS][CONF_ADDITIONAL_CONFIGS] if app["name"] not in APP_LIST ]) else: list_to_test = list(INPUT_LIST_WITH_APPS + APP_LIST) if CONF_ADDITIONAL_CONFIGS in device_config.get(CONF_APPS, {}): assert attr["source_list"].count(CURRENT_APP) == 1 for app_to_remove in INPUT_APPS: if app_to_remove in list_to_test: list_to_test.remove(app_to_remove) assert attr["source_list"] == list_to_test if app: assert app in attr["source_list"] or app == UNKNOWN_APP assert attr["source"] == app assert attr["app_name"] == app if app == UNKNOWN_APP: assert attr["app_id"] == app_config else: assert "app_id" not in attr else: assert attr["source"] == "CAST" assert "app_id" not in attr assert "app_name" not in attr assert (attr["volume_level"] == float( int(MAX_VOLUME[VIZIO_DEVICE_CLASS_TV] / 2)) / MAX_VOLUME[VIZIO_DEVICE_CLASS_TV])