From caa5578134bb8d31ef71c56ae8c75480dc2275e6 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Sun, 30 Jan 2022 01:15:49 +0200 Subject: [PATCH] Fix webostv configure sources when selected source is missing (#65195) * Fix webostv configure sources when selected source is missing * Add comment for filtering duplicates --- homeassistant/components/webostv/config_flow.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/webostv/config_flow.py b/homeassistant/components/webostv/config_flow.py index 2120635be91..3bf4f7c6aeb 100644 --- a/homeassistant/components/webostv/config_flow.py +++ b/homeassistant/components/webostv/config_flow.py @@ -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()), + ] + ) + )