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 <paulus@home-assistant.io>

* reduce

* black

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick Koston 2020-04-04 10:19:58 -05:00 committed by GitHub
parent b9b1cee403
commit 025cce3445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -128,8 +128,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_import(self, validated_input): async def async_step_import(self, validated_input):
"""Handle import.""" """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() self._abort_if_unique_id_configured()
# Everything was validated in remote async_setup_platform # Everything was validated in remote async_setup_platform
# all we do now is create. # all we do now is create.
return await self._async_create_entry_from_valid_input( 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 # Options from yaml are preserved, we will pull them out when
# we setup the config entry # we setup the config entry
data.update(_options_from_user_input(user_input)) 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): return self.async_create_entry(title=validated[CONF_NAME], data=data)
"""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
def _options_from_user_input(user_input): def _options_from_user_input(user_input):