Skip to content

Commit

Permalink
"otp_secret" is now a required field
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrunt57 authored Dec 31, 2024
1 parent 7c450e0 commit b2a75bd
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self):
(vol.Required(CONF_HASS_URL), str),
(vol.Required(CONF_EMAIL), str),
(vol.Required(CONF_PASSWORD), str),
(vol.Optional(CONF_OTPSECRET), str),
(vol.Required(CONF_OTPSECRET), str),
(vol.Optional(CONF_SECURITYCODE), str),
(vol.Optional(CONF_PUBLIC_URL), str),
(vol.Optional(CONF_INCLUDE_DEVICES, default=""), str),
Expand Down Expand Up @@ -190,7 +190,7 @@ async def async_step_user(self, user_input=None):
str,
),
(
vol.Optional(
vol.Required(
CONF_OTPSECRET, default=self.config.get(CONF_OTPSECRET, "")
),
str,
Expand Down Expand Up @@ -294,8 +294,8 @@ async def async_step_user(self, user_input=None):
self.login.email = self.config.get(CONF_EMAIL)
if self.config.get(CONF_PASSWORD):
self.login.password = self.config.get(CONF_PASSWORD)
if self.config.get(CONF_OTPSECRET):
self.login.set_totp(self.config.get(CONF_OTPSECRET, ""))
if self.config.get():
self.login.set_totp(self.config.get(CONF_OTPSECRET))
except AlexapyPyotpInvalidKey:
return self.async_show_form(
step_id="user",
Expand Down Expand Up @@ -348,7 +348,7 @@ async def async_step_user(self, user_input=None):
):
otp: str = self.login.get_totp_token()
if otp:
_LOGGER.debug("Generating OTP from %s", otp)
_LOGGER.debug("Generated OTP: %s", otp)
return self.async_show_form(
step_id="totp_register",
data_schema=vol.Schema(self.totp_register),
Expand Down Expand Up @@ -472,7 +472,7 @@ async def async_step_user_legacy(self, user_input=None):
password=self.config[CONF_PASSWORD],
outputpath=self.hass.config.path,
debug=self.config[CONF_DEBUG],
otp_secret=self.config.get(CONF_OTPSECRET, ""),
otp_secret=self[CONF_OTPSECRET],
uuid=uuid,
oauth_login=True,
)
Expand All @@ -486,7 +486,7 @@ async def async_step_user_legacy(self, user_input=None):
):
otp: str = self.login.get_totp_token()
if otp:
_LOGGER.debug("Generating OTP from %s", otp)
_LOGGER.debug("Generated OTP: %s", otp)
return self.async_show_form(
step_id="totp_register",
data_schema=vol.Schema(self.totp_register),
Expand Down Expand Up @@ -756,13 +756,8 @@ def _save_user_input_to_config(self, user_input=None) -> None:
self.config[CONF_SECURITYCODE] = self.securitycode
elif CONF_SECURITYCODE in self.config:
self.config.pop(CONF_SECURITYCODE)
if user_input.get(CONF_OTPSECRET) and user_input.get(CONF_OTPSECRET).replace(
" ", ""
):
if CONF_OTPSECRET in user_input:
self.config[CONF_OTPSECRET] = user_input[CONF_OTPSECRET].replace(" ", "")
elif user_input.get(CONF_OTPSECRET):
# a blank line
self.config.pop(CONF_OTPSECRET)
if CONF_EMAIL in user_input:
self.config[CONF_EMAIL] = user_input[CONF_EMAIL]
if CONF_PASSWORD in user_input:
Expand Down Expand Up @@ -952,7 +947,7 @@ async def async_step_init(
CONF_SECURITYCODE
]
if CONF_OTPSECRET in self._config_entry.data:
user_input[CONF_OTPSECRET] = self._config_entry.data[CONF_OTPSECRET]
user_input[CONF_OTPSECRET] = self._config_entry.data[CONF_OTPSECRET].replace(" ", "")
if CONF_OAUTH in self._config_entry.data:
user_input[CONF_OAUTH] = self._config_entry.data[CONF_OAUTH]
"""Ensure public_url ends with trailing slash"""
Expand Down

0 comments on commit b2a75bd

Please sign in to comment.