Skip to content

Commit

Permalink
check if 2FA is enabled after initial login
Browse files Browse the repository at this point in the history
  • Loading branch information
bbirnbach committed Nov 27, 2024
1 parent 92db410 commit f8ce019
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions custom_components/homeassistantedupage/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ class EdupageConfigFlow(config_entries.ConfigFlow, domain="homeassistantedupage"
def login(self, api, user_input):
try:
second_factor = api.login(user_input[CONF_USERNAME], user_input[CONF_PASSWORD], user_input[CONF_SUBDOMAIN])
# TODO: add user select as dropdown?! for 2FA
confirmation_method = "1"

if confirmation_method == "1":
#TODO: waiting does not work, maybe cause of async?! SecondFactorFailedException is raised if no breakpoint debug is set
while not second_factor.is_confirmed():
time.sleep(0.5)
second_factor.finish()

elif confirmation_method == "2":
# TODO: how to do this in HA?!
code = input("Enter 2FA code (or 'resend' to resend the code): ")
while code.lower() == "resend":
second_factor.resend_notifications()
if second_factor is not None:
# TODO: add user select as dropdown?! for 2FA
confirmation_method = "1"

if confirmation_method == "1":
#TODO: waiting does not work, maybe cause of async?! SecondFactorFailedException is raised if no breakpoint debug is set
while not second_factor.is_confirmed():
time.sleep(0.5)
second_factor.finish()

elif confirmation_method == "2":
# TODO: how to do this in HA?!
code = input("Enter 2FA code (or 'resend' to resend the code): ")
second_factor.finish_with_code(code)
while code.lower() == "resend":
second_factor.resend_notifications()
code = input("Enter 2FA code (or 'resend' to resend the code): ")
second_factor.finish_with_code(code)

except BadCredentialsException as e:
_LOGGER.error("Wrong username or password: %s", e)
Expand Down

0 comments on commit f8ce019

Please sign in to comment.