mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve calls to async_show_progress in matter (#107791)
This commit is contained in:
parent
2a0bd6654b
commit
fbb6c1d0f0
@ -76,19 +76,23 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Install Matter Server add-on."""
|
||||
if not self.install_task:
|
||||
self.install_task = self.hass.async_create_task(self._async_install_addon())
|
||||
|
||||
if not self.install_task.done():
|
||||
return self.async_show_progress(
|
||||
step_id="install_addon", progress_action="install_addon"
|
||||
step_id="install_addon",
|
||||
progress_action="install_addon",
|
||||
progress_task=self.install_task,
|
||||
)
|
||||
|
||||
try:
|
||||
await self.install_task
|
||||
except AddonError as err:
|
||||
self.install_task = None
|
||||
LOGGER.error(err)
|
||||
return self.async_show_progress_done(next_step_id="install_failed")
|
||||
finally:
|
||||
self.install_task = None
|
||||
|
||||
self.integration_created_addon = True
|
||||
self.install_task = None
|
||||
|
||||
return self.async_show_progress_done(next_step_id="start_addon")
|
||||
|
||||
@ -101,13 +105,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
async def _async_install_addon(self) -> None:
|
||||
"""Install the Matter Server add-on."""
|
||||
addon_manager: AddonManager = get_addon_manager(self.hass)
|
||||
try:
|
||||
await addon_manager.async_schedule_install_addon()
|
||||
finally:
|
||||
# Continue the flow after show progress when the task is done.
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.flow.async_configure(flow_id=self.flow_id)
|
||||
)
|
||||
|
||||
async def _async_get_addon_discovery_info(self) -> dict:
|
||||
"""Return add-on discovery info."""
|
||||
@ -126,18 +124,21 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Start Matter Server add-on."""
|
||||
if not self.start_task:
|
||||
self.start_task = self.hass.async_create_task(self._async_start_addon())
|
||||
if not self.start_task.done():
|
||||
return self.async_show_progress(
|
||||
step_id="start_addon", progress_action="start_addon"
|
||||
step_id="start_addon",
|
||||
progress_action="start_addon",
|
||||
progress_task=self.start_task,
|
||||
)
|
||||
|
||||
try:
|
||||
await self.start_task
|
||||
except (FailedConnect, AddonError, AbortFlow) as err:
|
||||
self.start_task = None
|
||||
LOGGER.error(err)
|
||||
return self.async_show_progress_done(next_step_id="start_failed")
|
||||
|
||||
finally:
|
||||
self.start_task = None
|
||||
|
||||
return self.async_show_progress_done(next_step_id="finish_addon_setup")
|
||||
|
||||
async def async_step_start_failed(
|
||||
@ -150,7 +151,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Start the Matter Server add-on."""
|
||||
addon_manager: AddonManager = get_addon_manager(self.hass)
|
||||
|
||||
try:
|
||||
await addon_manager.async_schedule_start_addon()
|
||||
# Sleep some seconds to let the add-on start properly before connecting.
|
||||
for _ in range(ADDON_SETUP_TIMEOUT_ROUNDS):
|
||||
@ -172,11 +172,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
break
|
||||
else:
|
||||
raise FailedConnect("Failed to start Matter Server add-on: timeout")
|
||||
finally:
|
||||
# Continue the flow after show progress when the task is done.
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.flow.async_configure(flow_id=self.flow_id)
|
||||
)
|
||||
|
||||
async def _async_get_addon_info(self) -> AddonInfo:
|
||||
"""Return Matter Server add-on info."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user