Add confirmation to Cast/Sonos/iOS config entries (#16769)

* Add confirmation to Cast/Sonos/iOS config entries

* Remove redundant code
This commit is contained in:
Paulus Schoutsen 2018-09-21 16:34:37 +02:00 committed by Pascal Vizeli
parent 213171769d
commit 8b42d0c471
5 changed files with 59 additions and 33 deletions

View file

@ -31,40 +31,39 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
reason='single_instance_allowed'
)
# Get current discovered entries.
in_progress = self._async_in_progress()
return await self.async_step_confirm()
has_devices = in_progress
if not has_devices:
has_devices = await self.hass.async_add_job(
self._discovery_function, self.hass)
if not has_devices:
return self.async_abort(
reason='no_devices_found'
async def async_step_confirm(self, user_input=None):
"""Confirm setup."""
if user_input is None:
return self.async_show_form(
step_id='confirm',
)
# Cancel the discovered one.
for flow in in_progress:
self.hass.config_entries.flow.async_abort(flow['flow_id'])
if self.context and self.context.get('source') != \
config_entries.SOURCE_DISCOVERY:
# Get current discovered entries.
in_progress = self._async_in_progress()
has_devices = in_progress
if not has_devices:
has_devices = await self.hass.async_add_job(
self._discovery_function, self.hass)
if not has_devices:
return self.async_abort(
reason='no_devices_found'
)
# Cancel the discovered one.
for flow in in_progress:
self.hass.config_entries.flow.async_abort(flow['flow_id'])
return self.async_create_entry(
title=self._title,
data={},
)
async def async_step_confirm(self, user_input=None):
"""Confirm setup."""
if user_input is not None:
return self.async_create_entry(
title=self._title,
data={},
)
return self.async_show_form(
step_id='confirm',
)
async def async_step_discovery(self, discovery_info):
"""Handle a flow initialized by discovery."""
if self._async_in_progress() or self._async_current_entries():