Reduce boilerplate to abort for matching config entries (#50186)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
d6a202bd74
commit
34c84a6bbb
49 changed files with 183 additions and 350 deletions
|
@ -85,8 +85,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
parsed_url = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION])
|
||||
friendly_name = discovery_info[ssdp.ATTR_UPNP_FRIENDLY_NAME]
|
||||
|
||||
if self._host_already_configured(parsed_url.hostname):
|
||||
return self.async_abort(reason="already_configured")
|
||||
self._async_abort_entries_match({CONF_HOST: parsed_url.hostname})
|
||||
|
||||
self.context["title_placeholders"] = {"name": friendly_name}
|
||||
|
||||
|
@ -147,16 +146,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
return self.async_create_entry(title=validated[CONF_NAME], data=data)
|
||||
|
||||
def _host_already_configured(self, host):
|
||||
"""See if we already have a harmony entry matching the host."""
|
||||
for entry in self._async_current_entries():
|
||||
if CONF_HOST not in entry.data:
|
||||
continue
|
||||
|
||||
if entry.data[CONF_HOST] == host:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _options_from_user_input(user_input):
|
||||
options = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue