Skip to content

Commit

Permalink
removed raising exception
Browse files Browse the repository at this point in the history
  • Loading branch information
vaproloff committed Nov 11, 2024
1 parent ca0a855 commit 4062546
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions custom_components/tion/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_create_clientsession

from .client import TionClient
Expand Down Expand Up @@ -70,25 +69,24 @@ async def async_step_user(

if auth_data is None:
errors["base"] = "invalid_auth"
raise ConfigEntryAuthFailed

sha256_hash = hashlib.new("sha256")
sha256_hash.update(user_input[CONF_USERNAME].encode())
unique_id = f"{sha256_hash.hexdigest()}"

# Checks that the device is actually unique, otherwise abort
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=user_input[CONF_USERNAME],
data={
CONF_USERNAME: user_input[CONF_USERNAME],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_SCAN_INTERVAL: interval,
AUTH_DATA: auth_data,
},
)
else:
sha256_hash = hashlib.new("sha256")
sha256_hash.update(user_input[CONF_USERNAME].encode())
unique_id = f"{sha256_hash.hexdigest()}"

# Checks that the device is actually unique, otherwise abort
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=user_input[CONF_USERNAME],
data={
CONF_USERNAME: user_input[CONF_USERNAME],
CONF_PASSWORD: user_input[CONF_PASSWORD],
CONF_SCAN_INTERVAL: interval,
AUTH_DATA: auth_data,
},
)

return self.async_show_form(
step_id="user",
Expand Down

0 comments on commit 4062546

Please sign in to comment.