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
pull/32211/head
Raman Gupta 2020-02-24 22:35:28 -05:00 committed by Paulus Schoutsen
parent 45d63e22d5
commit 5dc93aeeb1
2 changed files with 13 additions and 8 deletions

View File

@ -177,11 +177,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()

View File

@ -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,