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 Paulus Schoutsen
parent d6527953c3
commit 5368fb6d54

View File

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