diff --git a/custom_components/alexa_media/__init__.py b/custom_components/alexa_media/__init__.py index 67e3c4de..c2198b9d 100644 --- a/custom_components/alexa_media/__init__.py +++ b/custom_components/alexa_media/__init__.py @@ -27,6 +27,7 @@ ) import async_timeout from homeassistant import util +from homeassistant.components.persistent_notification import async_creat from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( CONF_EMAIL, @@ -45,6 +46,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.util import dt, slugify +from httpx import TimeoutException import voluptuous as vol from .alexa_entity import AlexaEntityData, get_entity_data, parse_alexa_entities @@ -176,9 +178,10 @@ async def async_setup(hass, config, discovery_info=None): DOMAIN, context={"source": SOURCE_IMPORT}, data={ + CONF_URL: account[CONF_URL], CONF_EMAIL: account[CONF_EMAIL], CONF_PASSWORD: account[CONF_PASSWORD], - CONF_URL: account[CONF_URL], + CONF_PUBLIC_URL: account[CONF_PUBLIC_URL], CONF_INCLUDE_DEVICES: account[CONF_INCLUDE_DEVICES], CONF_EXCLUDE_DEVICES: account[CONF_EXCLUDE_DEVICES], CONF_SCAN_INTERVAL: account[CONF_SCAN_INTERVAL].total_seconds(), @@ -1387,7 +1390,8 @@ async def test_login_status(hass, config_entry, login) -> bool: elaspsed_time: str = str(datetime.now() - login.stats.get("login_timestamp")) api_calls: int = login.stats.get("api_calls") message += f"Relogin required after {elaspsed_time} and {api_calls} api calls." - hass.components.persistent_notification.async_create( + # hass.components.persistent_notification.async_create( + async_create( title="Alexa Media Reauthentication Required", message=message, notification_id=f"alexa_media_{slugify(login.email)}{slugify(login.url[7:])}", diff --git a/custom_components/alexa_media/config_flow.py b/custom_components/alexa_media/config_flow.py index 8b8eb9bf..35eae321 100644 --- a/custom_components/alexa_media/config_flow.py +++ b/custom_components/alexa_media/config_flow.py @@ -124,6 +124,7 @@ def __init__(self): (vol.Required(CONF_PASSWORD), str), (vol.Optional(CONF_OTPSECRET), str), (vol.Optional(CONF_SECURITYCODE), str), + (vol.Optional(CONF_PUBLIC_URL), str), (vol.Optional(CONF_INCLUDE_DEVICES, default=""), str), (vol.Optional(CONF_EXCLUDE_DEVICES, default=""), str), (vol.Optional(CONF_SCAN_INTERVAL, default=60), int), @@ -151,6 +152,7 @@ async def async_step_user(self, user_input=None): hass_url: str = get_url(self.hass, prefer_external=True) except NoURLAvailableError: hass_url = "" + DEFAULT_PUBLIC_URL = hass_url self.proxy_schema = OrderedDict( [ ( @@ -182,6 +184,13 @@ async def async_step_user(self, user_input=None): ), str, ), + ( + vol.Optional( + CONF_PUBLIC_URL, + default=self.config.get(CONF_PUBLIC_URL, DEFAULT_PUBLIC_URL), + ), + str, + ), ( vol.Optional( CONF_INCLUDE_DEVICES, @@ -738,8 +747,10 @@ def _save_user_input_to_config(self, user_input=None) -> None: self.config[CONF_EMAIL] = user_input[CONF_EMAIL] if CONF_PASSWORD in user_input: self.config[CONF_PASSWORD] = user_input[CONF_PASSWORD] - if CONF_HASS_URL in user_input: - self.config[CONF_HASS_URL] = user_input[CONF_HASS_URL] + if CONF_URL in user_input: + self.config[CONF_URL] = user_input[CONF_URL] + if CONF_PUBLIC_URL in user_input: + self.config[CONF_PUBLIC_URL] = user_input[CONF_PUBLIC_URL] if CONF_SCAN_INTERVAL in user_input: self.config[CONF_SCAN_INTERVAL] = ( user_input[CONF_SCAN_INTERVAL] @@ -792,6 +803,13 @@ def _update_schema_defaults(self) -> Any: CONF_OTPSECRET, default=self.config.get(CONF_OTPSECRET, ""), ): str, + vol.Required( + CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url) + ): str, + vol.Optional( + CONF_PUBLIC_URL, + default=self.config.get(CONF_PUBLIC_URL, DEFAULT_PUBLIC_URL), + ): str, vol.Optional( CONF_INCLUDE_DEVICES, default=self.config.get(CONF_INCLUDE_DEVICES, ""), @@ -845,6 +863,15 @@ async def async_step_init( self.options_schema = OrderedDict( [ + ( + vol.Optional( + CONF_PUBLIC_URL, + default=self.config_entry.data.get( + CONF_PUBLIC_URL, DEFAULT_PUBLIC_URL + ), + ), + str, + ), ( vol.Optional( CONF_INCLUDE_DEVICES,