Fix vizio bug that occurs when CONF_APPS isn't in config entry… (#33857)
* 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
This commit is contained in:
parent
daf941e771
commit
b46eee04e4
2 changed files with 36 additions and 2 deletions
|
@ -125,8 +125,8 @@ class VizioOptionsConfigFlow(config_entries.OptionsFlow):
|
||||||
default_include_or_exclude = (
|
default_include_or_exclude = (
|
||||||
CONF_EXCLUDE
|
CONF_EXCLUDE
|
||||||
if self.config_entry.options
|
if self.config_entry.options
|
||||||
and CONF_EXCLUDE in self.config_entry.options.get(CONF_APPS)
|
and CONF_EXCLUDE in self.config_entry.options.get(CONF_APPS, {})
|
||||||
else CONF_EXCLUDE
|
else CONF_INCLUDE
|
||||||
)
|
)
|
||||||
options.update(
|
options.update(
|
||||||
{
|
{
|
||||||
|
|
|
@ -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.config_flow import _get_config_schema
|
||||||
from homeassistant.components.vizio.const import (
|
from homeassistant.components.vizio.const import (
|
||||||
CONF_APPS,
|
CONF_APPS,
|
||||||
|
CONF_APPS_TO_INCLUDE_OR_EXCLUDE,
|
||||||
CONF_INCLUDE,
|
CONF_INCLUDE,
|
||||||
CONF_VOLUME_STEP,
|
CONF_VOLUME_STEP,
|
||||||
DEFAULT_NAME,
|
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]}
|
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(
|
async def test_user_host_already_configured(
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistantType,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
|
|
Loading…
Add table
Reference in a new issue