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
This commit is contained in:
Raman Gupta 2020-02-24 22:35:28 -05:00 committed by GitHub
parent 71a6ea1c10
commit 4236d62b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -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()

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,