From 025cce3445b09e3cf4291e40af9801393c0f9f64 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 4 Apr 2020 10:19:58 -0500 Subject: [PATCH] Handle race condition in harmony setup (#33611) * Handle race condition in harmony setup If the remote was discovered via ssdp before the yaml config import happened, the unique id would already be set and the import would abort. * Update homeassistant/components/harmony/config_flow.py Co-Authored-By: Paulus Schoutsen * reduce * black Co-authored-by: Paulus Schoutsen --- homeassistant/components/harmony/config_flow.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/harmony/config_flow.py b/homeassistant/components/harmony/config_flow.py index 9d9c9dfb8e9..8d43b2d69ca 100644 --- a/homeassistant/components/harmony/config_flow.py +++ b/homeassistant/components/harmony/config_flow.py @@ -128,8 +128,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_import(self, validated_input): """Handle import.""" - await self.async_set_unique_id(validated_input[UNIQUE_ID]) + await self.async_set_unique_id( + validated_input[UNIQUE_ID], raise_on_progress=False + ) self._abort_if_unique_id_configured() + # Everything was validated in remote async_setup_platform # all we do now is create. return await self._async_create_entry_from_valid_input( @@ -149,14 +152,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # Options from yaml are preserved, we will pull them out when # we setup the config entry data.update(_options_from_user_input(user_input)) - return self.async_create_entry(title=validated[CONF_NAME], data=data) - def _host_already_configured(self, user_input): - """See if we already have a harmony matching user input configured.""" - existing_hosts = { - entry.data[CONF_HOST] for entry in self._async_current_entries() - } - return user_input[CONF_HOST] in existing_hosts + return self.async_create_entry(title=validated[CONF_NAME], data=data) def _options_from_user_input(user_input):