Skip to content

Commit

Permalink
fix: fix configuration.yaml import code
Browse files Browse the repository at this point in the history
The import will now search config entries by data values instead of by title which
can be change in HA 109. The code also properly creates a new entry
after failing a search.
closes #665
  • Loading branch information
alandtse committed Apr 30, 2020
1 parent 6a3631d commit fc6b97e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,20 @@ async def async_setup(hass, config, discovery_info=None):

domainconfig = config.get(DOMAIN)
for account in domainconfig[CONF_ACCOUNTS]:
entry_title = "{} - {}".format(account[CONF_EMAIL], account[CONF_URL])
entry_found = False
_LOGGER.debug(
"Importing config information for %s - %s from configuration.yaml",
hide_email(account[CONF_EMAIL]),
account[CONF_URL],
)
if entry_title in configured_instances(hass):
if hass.config_entries.async_entries(DOMAIN):
_LOGGER.debug("Found existing config entries")
for entry in hass.config_entries.async_entries(DOMAIN):
if entry_title == entry.title:
if (
entry.data.get(CONF_EMAIL) == account[CONF_EMAIL]
and entry.data.get(CONF_URL) == account[CONF_URL]
):
_LOGGER.debug("Updating existing entry")
hass.config_entries.async_update_entry(
entry,
data={
Expand All @@ -137,8 +142,10 @@ async def async_setup(hass, config, discovery_info=None):
].total_seconds(),
},
)
entry_found = True
break
else:
if not entry_found:
_LOGGER.debug("Creating new config entry")
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
Expand Down

0 comments on commit fc6b97e

Please sign in to comment.