Fix webostv configure sources when selected source is missing (#65195)

* Fix webostv configure sources when selected source is missing

* Add comment for filtering duplicates
This commit is contained in:
Shay Levy 2022-01-30 01:15:49 +02:00 committed by GitHub
parent 30440cd1ba
commit caa5578134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -178,11 +178,14 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
options_input = {CONF_SOURCES: user_input[CONF_SOURCES]}
return self.async_create_entry(title="", data=options_input)
# Get sources
sources = self.options.get(CONF_SOURCES, "")
sources_list = await async_get_sources(self.host, self.key)
if not sources_list:
errors["base"] = "cannot_retrieve"
sources = [s for s in self.options.get(CONF_SOURCES, []) if s in sources_list]
if not sources:
sources = sources_list
options_schema = vol.Schema(
{
vol.Optional(
@ -204,7 +207,11 @@ async def async_get_sources(host: str, key: str) -> list[str]:
except WEBOSTV_EXCEPTIONS:
return []
return [
*(app["title"] for app in client.apps.values()),
*(app["label"] for app in client.inputs.values()),
]
return list(
dict.fromkeys( # Preserve order when filtering duplicates
[
*(app["title"] for app in client.apps.values()),
*(app["label"] for app in client.inputs.values()),
]
)
)