From 309989be8950b983f95d69e39ad4cb062f0944c2 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 24 Feb 2020 17:37:54 -0500 Subject: [PATCH] Fix vizio bug to use 'get' to get volume_step since it is optional (#32151) * use get to get volume_step since it is optional * always set volume_step to default in options and data if its not included --- homeassistant/components/vizio/config_flow.py | 7 +++++-- tests/components/vizio/test_config_flow.py | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index c62222f2d91..cde84a6a9e2 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -180,8 +180,11 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): if entry.data[CONF_NAME] != import_config[CONF_NAME]: updated_name[CONF_NAME] = import_config[CONF_NAME] - if entry.data[CONF_VOLUME_STEP] != import_config[CONF_VOLUME_STEP]: - updated_options[CONF_VOLUME_STEP] = import_config[CONF_VOLUME_STEP] + import_volume_step = import_config.get( + CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP + ) + if entry.data.get(CONF_VOLUME_STEP) != import_volume_step: + updated_options[CONF_VOLUME_STEP] = import_volume_step if updated_options or updated_name: new_data = entry.data.copy() diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index 416617d4b9b..2dd32800c2d 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -300,15 +300,15 @@ async def test_import_flow_update_options( result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, - data=vol.Schema(VIZIO_SCHEMA)(MOCK_IMPORT_VALID_TV_CONFIG), + data=vol.Schema(VIZIO_SCHEMA)(MOCK_SPEAKER_CONFIG), ) await hass.async_block_till_done() - assert result["result"].options == {CONF_VOLUME_STEP: VOLUME_STEP} + assert result["result"].options == {CONF_VOLUME_STEP: DEFAULT_VOLUME_STEP} assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY entry_id = result["result"].entry_id - updated_config = MOCK_IMPORT_VALID_TV_CONFIG.copy() + updated_config = MOCK_SPEAKER_CONFIG.copy() updated_config[CONF_VOLUME_STEP] = VOLUME_STEP + 1 result = await hass.config_entries.flow.async_init( DOMAIN,