Skip to content

Commit

Permalink
fix: check for missing hass_url during auto reauth
Browse files Browse the repository at this point in the history
Reauth attempts may not have a hass url configured. Now, it will try to
generate it or request it from the user.

closes #1702
  • Loading branch information
alandtse committed Sep 7, 2022
1 parent 58af5b3 commit 7d181a3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,17 @@ async def async_step_user(self, user_input=None):
errors={"base": "2fa_key_invalid"},
description_placeholders={"message": ""},
)
hass_url: str = user_input.get(CONF_HASS_URL)
try:
hass_url: str = user_input.get(
CONF_HASS_URL, get_url(self.hass, prefer_external=True)
)
except NoURLAvailableError:
_LOGGER.debug("No Home Assistant URL found in config or detected; forcing user form")
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(self.proxy_schema),
description_placeholders={"message": ""},
)
hass_url_valid: bool = False
hass_url_error: str = ""
async with ClientSession() as session:
Expand All @@ -268,9 +278,9 @@ async def async_step_user(self, user_input=None):
description_placeholders={
"email": self.login.email,
"hass_url": hass_url,
"error": hass_url_error
"error": hass_url_error,
},
)
)
if (
user_input
and user_input.get(CONF_OTPSECRET)
Expand Down Expand Up @@ -301,7 +311,8 @@ async def async_step_start_proxy(self, user_input=None):
if not self.proxy:
try:
self.proxy = AlexaProxy(
self.login, str(URL(self.config.get(CONF_HASS_URL)).with_path(AUTH_PROXY_PATH))
self.login,
str(URL(self.config.get(CONF_HASS_URL)).with_path(AUTH_PROXY_PATH)),
)
except ValueError as ex:
return self.async_show_form(
Expand Down Expand Up @@ -558,7 +569,7 @@ async def _test_login(self):
"access_token": login.access_token,
"refresh_token": login.refresh_token,
"expires_in": login.expires_in,
"mac_dms": login.mac_dms
"mac_dms": login.mac_dms,
}
self.hass.data.setdefault(
DATA_ALEXAMEDIA,
Expand Down

0 comments on commit 7d181a3

Please sign in to comment.