mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Improve calls to async_show_progress in zwave_js (#107794)
This commit is contained in:
parent
24cd6a8a52
commit
2a0bd6654b
@ -185,19 +185,23 @@ class BaseZwaveJSFlow(FlowHandler, ABC):
|
|||||||
"""Install Z-Wave JS add-on."""
|
"""Install Z-Wave JS add-on."""
|
||||||
if not self.install_task:
|
if not self.install_task:
|
||||||
self.install_task = self.hass.async_create_task(self._async_install_addon())
|
self.install_task = self.hass.async_create_task(self._async_install_addon())
|
||||||
|
|
||||||
|
if not self.install_task.done():
|
||||||
return self.async_show_progress(
|
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:
|
try:
|
||||||
await self.install_task
|
await self.install_task
|
||||||
except AddonError as err:
|
except AddonError as err:
|
||||||
self.install_task = None
|
|
||||||
_LOGGER.error(err)
|
_LOGGER.error(err)
|
||||||
return self.async_show_progress_done(next_step_id="install_failed")
|
return self.async_show_progress_done(next_step_id="install_failed")
|
||||||
|
finally:
|
||||||
|
self.install_task = None
|
||||||
|
|
||||||
self.integration_created_addon = True
|
self.integration_created_addon = True
|
||||||
self.install_task = None
|
|
||||||
|
|
||||||
return self.async_show_progress_done(next_step_id="configure_addon")
|
return self.async_show_progress_done(next_step_id="configure_addon")
|
||||||
|
|
||||||
@ -213,18 +217,22 @@ class BaseZwaveJSFlow(FlowHandler, ABC):
|
|||||||
"""Start Z-Wave JS add-on."""
|
"""Start Z-Wave JS add-on."""
|
||||||
if not self.start_task:
|
if not self.start_task:
|
||||||
self.start_task = self.hass.async_create_task(self._async_start_addon())
|
self.start_task = self.hass.async_create_task(self._async_start_addon())
|
||||||
|
|
||||||
|
if not self.start_task.done():
|
||||||
return self.async_show_progress(
|
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:
|
try:
|
||||||
await self.start_task
|
await self.start_task
|
||||||
except (CannotConnect, AddonError, AbortFlow) as err:
|
except (CannotConnect, AddonError, AbortFlow) as err:
|
||||||
self.start_task = None
|
|
||||||
_LOGGER.error(err)
|
_LOGGER.error(err)
|
||||||
return self.async_show_progress_done(next_step_id="start_failed")
|
return self.async_show_progress_done(next_step_id="start_failed")
|
||||||
|
finally:
|
||||||
self.start_task = None
|
self.start_task = None
|
||||||
|
|
||||||
return self.async_show_progress_done(next_step_id="finish_addon_setup")
|
return self.async_show_progress_done(next_step_id="finish_addon_setup")
|
||||||
|
|
||||||
async def async_step_start_failed(
|
async def async_step_start_failed(
|
||||||
@ -237,7 +245,6 @@ class BaseZwaveJSFlow(FlowHandler, ABC):
|
|||||||
"""Start the Z-Wave JS add-on."""
|
"""Start the Z-Wave JS add-on."""
|
||||||
addon_manager: AddonManager = get_addon_manager(self.hass)
|
addon_manager: AddonManager = get_addon_manager(self.hass)
|
||||||
self.version_info = None
|
self.version_info = None
|
||||||
try:
|
|
||||||
if self.restart_addon:
|
if self.restart_addon:
|
||||||
await addon_manager.async_schedule_restart_addon()
|
await addon_manager.async_schedule_restart_addon()
|
||||||
else:
|
else:
|
||||||
@ -264,11 +271,6 @@ class BaseZwaveJSFlow(FlowHandler, ABC):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise CannotConnect("Failed to start Z-Wave JS add-on: timeout")
|
raise CannotConnect("Failed to start Z-Wave JS add-on: timeout")
|
||||||
finally:
|
|
||||||
# Continue the flow after show progress when the task is done.
|
|
||||||
self.hass.async_create_task(
|
|
||||||
self.flow_manager.async_configure(flow_id=self.flow_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def async_step_configure_addon(
|
async def async_step_configure_addon(
|
||||||
@ -309,13 +311,7 @@ class BaseZwaveJSFlow(FlowHandler, ABC):
|
|||||||
async def _async_install_addon(self) -> None:
|
async def _async_install_addon(self) -> None:
|
||||||
"""Install the Z-Wave JS add-on."""
|
"""Install the Z-Wave JS add-on."""
|
||||||
addon_manager: AddonManager = get_addon_manager(self.hass)
|
addon_manager: AddonManager = get_addon_manager(self.hass)
|
||||||
try:
|
|
||||||
await addon_manager.async_schedule_install_addon()
|
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.flow_manager.async_configure(flow_id=self.flow_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _async_get_addon_discovery_info(self) -> dict:
|
async def _async_get_addon_discovery_info(self) -> dict:
|
||||||
"""Return add-on discovery info."""
|
"""Return add-on discovery info."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user