From 4236d62b44d6481be356025d02594116b544f0bf Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 24 Feb 2020 22:35:28 -0500 Subject: [PATCH] Improve Vizio fix to avoid KeyError (#32163) * dont set default volume_step on import check * ensure config entry data['volume_step'] is set * consolidate entry update during entry setup --- homeassistant/components/vizio/config_flow.py | 7 ++----- homeassistant/components/vizio/media_player.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index cde84a6a9e2..969d387a26b 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -180,11 +180,8 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): if entry.data[CONF_NAME] != import_config[CONF_NAME]: updated_name[CONF_NAME] = import_config[CONF_NAME] - 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 entry.data.get(CONF_VOLUME_STEP) != import_config[CONF_VOLUME_STEP]: + updated_options[CONF_VOLUME_STEP] = import_config[CONF_VOLUME_STEP] if updated_options or updated_name: new_data = entry.data.copy() diff --git a/homeassistant/components/vizio/media_player.py b/homeassistant/components/vizio/media_player.py index 13554ab8f36..6b62d6bafd0 100644 --- a/homeassistant/components/vizio/media_player.py +++ b/homeassistant/components/vizio/media_player.py @@ -56,10 +56,18 @@ async def async_setup_entry( volume_step = config_entry.options.get( CONF_VOLUME_STEP, config_entry.data.get(CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP), ) + + params = {} if not config_entry.options: - hass.config_entries.async_update_entry( - config_entry, options={CONF_VOLUME_STEP: volume_step} - ) + params["options"] = {CONF_VOLUME_STEP: volume_step} + + if not config_entry.data.get(CONF_VOLUME_STEP): + new_data = config_entry.data.copy() + new_data.update({CONF_VOLUME_STEP: volume_step}) + params["data"] = new_data + + if params: + hass.config_entries.async_update_entry(config_entry, **params) device = VizioAsync( DEVICE_ID,