Reduce boilerplate to abort for matching config entries (#50186)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
J. Nick Koston 2021-05-11 15:00:12 -05:00 committed by GitHub
parent d6a202bd74
commit 34c84a6bbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 183 additions and 350 deletions

View file

@ -225,8 +225,7 @@ class UnifiFlowHandler(config_entries.ConfigFlow, domain=UNIFI_DOMAIN):
CONF_HOST: parsed_url.hostname,
}
if self._host_already_configured(self.config[CONF_HOST]):
return self.async_abort(reason="already_configured")
self._async_abort_entries_match({CONF_HOST: self.config[CONF_HOST]})
await self.async_set_unique_id(mac_address)
self._abort_if_unique_id_configured(updates=self.config)
@ -242,13 +241,6 @@ class UnifiFlowHandler(config_entries.ConfigFlow, domain=UNIFI_DOMAIN):
return await self.async_step_user()
def _host_already_configured(self, host):
"""See if we already have a UniFi entry matching the host."""
for entry in self._async_current_entries():
if entry.data.get(CONF_HOST) == host:
return True
return False
class UnifiOptionsFlowHandler(config_entries.OptionsFlow):
"""Handle Unifi options."""