Update vizio host check to handle entries that don't have port (#31463)

* Update vizio host check to handle entries that don't have port

* add comment explaining no_port test for future

* remove _name_is_same function and support user updating name in config

* Update strings.json

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Raman GuptaandPaulus Schoutsen authored and GitHub committed 2020-02-04 11:31:03 -08:00
1 parent 8af9585f12
commit 1efea50654
3 files changed
+78 -12

No files matched your search

+21 -9
View File
@@ -53,6 +53,11 @@ def _get_config_flow_schema(input_dict: Dict[str, Any] = None) -> vol.Schema:
)
def _host_is_same(host1: str, host2: str) -> bool:
"""Check if host1 and host2 are the same."""
return host1.split(":")[0] == host2.split(":")[0]
class VizioOptionsConfigFlow(config_entries.OptionsFlow):
"""Handle Transmission client options."""
@@ -108,7 +113,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
# Check if new config entry matches any existing config entries
for entry in self.hass.config_entries.async_entries(DOMAIN):
if entry.data[CONF_HOST] == user_input[CONF_HOST]:
if _host_is_same(entry.data[CONF_HOST], user_input[CONF_HOST]):
errors[CONF_HOST] = "host_exists"
break
@@ -165,24 +170,31 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Import a config entry from configuration.yaml."""
# Check if new config entry matches any existing config entries
for entry in self.hass.config_entries.async_entries(DOMAIN):
if entry.data[CONF_HOST] == import_config[CONF_HOST] and entry.data[
CONF_NAME
] == import_config.get(CONF_NAME):
if _host_is_same(entry.data[CONF_HOST], import_config[CONF_HOST]):
updated_options = {}
updated_name = {}
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]
if updated_options:
if updated_options or updated_name:
new_data = entry.data.copy()
new_data.update(updated_options)
new_options = entry.options.copy()
new_options.update(updated_options)
if updated_name:
new_data.update(updated_name)
if updated_options:
new_data.update(updated_options)
new_options.update(updated_options)
self.hass.config_entries.async_update_entry(
entry=entry, data=new_data, options=new_options,
)
return self.async_abort(reason="updated_options")
return self.async_abort(reason="updated_entry")
return self.async_abort(reason="already_setup")
@@ -199,7 +211,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
# Check if new config entry matches any existing config entries and abort if so
for entry in self.hass.config_entries.async_entries(DOMAIN):
if entry.data[CONF_HOST] == discovery_info[CONF_HOST]:
if _host_is_same(entry.data[CONF_HOST], discovery_info[CONF_HOST]):
return self.async_abort(reason="already_setup")
# Set default name to discovered device name by stripping zeroconf service
+2 -2
View File
@@ -21,7 +21,7 @@
"abort": {
"already_setup": "This entry has already been setup.",
"already_setup_with_diff_host_and_name": "This entry appears to have already been setup with a different host and name based on its serial number. Please remove any old entries from your configuration.yaml and from the Integrations menu before reattempting to add this device.",
"updated_options": "This entry has already been setup but the options defined in the config do not match the previously imported options values so the config entry has been updated accordingly."
"updated_entry": "This entry has already been setup but the name and/or options defined in the config do not match the previously imported config so the config entry has been updated accordingly."
}
},
"options": {
@@ -35,4 +35,4 @@
}
}
}
}
}