From b46eee04e475a1211e10252bca30c4a46f1d474e Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 8 Apr 2020 23:44:33 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20vizio=20bug=20that=20occurs=20when=20CONF?= =?UTF-8?q?=5FAPPS=20isn't=20in=20config=20entry=E2=80=A6=20(#33857)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix bug when search for string in dict fails when dict is null * another bug fix that I only noticed because of this other bug * add test to cover failure scenario * update docstring * add additional assertions to cover failure scenario that's being fixed --- homeassistant/components/vizio/config_flow.py | 4 +-- tests/components/vizio/test_config_flow.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index ba3ac5107bb..51f00ad98bb 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -125,8 +125,8 @@ class VizioOptionsConfigFlow(config_entries.OptionsFlow): default_include_or_exclude = ( CONF_EXCLUDE if self.config_entry.options - and CONF_EXCLUDE in self.config_entry.options.get(CONF_APPS) - else CONF_EXCLUDE + and CONF_EXCLUDE in self.config_entry.options.get(CONF_APPS, {}) + else CONF_INCLUDE ) options.update( { diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index a8a760d8ca2..b5b10534759 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -9,6 +9,7 @@ from homeassistant.components.media_player import DEVICE_CLASS_SPEAKER, DEVICE_C from homeassistant.components.vizio.config_flow import _get_config_schema from homeassistant.components.vizio.const import ( CONF_APPS, + CONF_APPS_TO_INCLUDE_OR_EXCLUDE, CONF_INCLUDE, CONF_VOLUME_STEP, DEFAULT_NAME, @@ -176,6 +177,39 @@ async def test_tv_options_flow_with_apps(hass: HomeAssistantType) -> None: assert result["data"][CONF_APPS] == {CONF_INCLUDE: [CURRENT_APP]} +async def test_tv_options_flow_start_with_volume(hass: HomeAssistantType) -> None: + """Test options config flow for TV with providing apps option after providing volume step in initial config.""" + entry = MockConfigEntry( + domain=DOMAIN, + data=MOCK_USER_VALID_TV_CONFIG, + options={CONF_VOLUME_STEP: VOLUME_STEP}, + ) + entry.add_to_hass(hass) + + assert entry.options + assert entry.options == {CONF_VOLUME_STEP: VOLUME_STEP} + assert CONF_APPS not in entry.options + assert CONF_APPS_TO_INCLUDE_OR_EXCLUDE not in entry.options + + result = await hass.config_entries.options.async_init(entry.entry_id, data=None) + + assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["step_id"] == "init" + + options = {CONF_VOLUME_STEP: VOLUME_STEP} + options.update(MOCK_INCLUDE_APPS) + + result = await hass.config_entries.options.async_configure( + result["flow_id"], user_input=options + ) + + assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result["title"] == "" + assert result["data"][CONF_VOLUME_STEP] == VOLUME_STEP + assert CONF_APPS in result["data"] + assert result["data"][CONF_APPS] == {CONF_INCLUDE: [CURRENT_APP]} + + async def test_user_host_already_configured( hass: HomeAssistantType, vizio_connect: pytest.fixture,