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
|
@ -28,8 +28,7 @@ class GoalZeroFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
host = user_input[CONF_HOST]
|
||||
name = user_input[CONF_NAME]
|
||||
|
||||
if await self._async_endpoint_existed(host):
|
||||
return self.async_abort(reason="already_configured")
|
||||
self._async_abort_entries_match({CONF_HOST: host})
|
||||
|
||||
try:
|
||||
await self._async_try_connect(host)
|
||||
|
@ -64,12 +63,6 @@ class GoalZeroFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def _async_endpoint_existed(self, endpoint):
|
||||
for entry in self._async_current_entries():
|
||||
if endpoint == entry.data.get(CONF_HOST):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def _async_try_connect(self, host):
|
||||
session = async_get_clientsession(self.hass)
|
||||
api = Yeti(host, self.hass.loop, session)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue