Skip to content

Commit

Permalink
Merge pull request #2383 from alandtse/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Aug 2, 2024
2 parents 7224138 + 9755e3f commit 085c756
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 6 additions & 2 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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:])}",
Expand Down
31 changes: 29 additions & 2 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
[
(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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, ""),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 085c756

Please sign in to comment.