Add show progress to ozw config flow (#43310)
This commit is contained in:
parent
7ad2a6be30
commit
3f5d7e85c3
4 changed files with 55 additions and 4 deletions
|
@ -36,6 +36,7 @@ class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self.use_addon = False
|
self.use_addon = False
|
||||||
# If we install the add-on we should uninstall it on entry remove.
|
# If we install the add-on we should uninstall it on entry remove.
|
||||||
self.integration_created_addon = False
|
self.integration_created_addon = False
|
||||||
|
self.install_task = None
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
|
@ -93,16 +94,27 @@ class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
return await self.async_step_install_addon()
|
return await self.async_step_install_addon()
|
||||||
|
|
||||||
async def async_step_install_addon(self):
|
async def async_step_install_addon(self, user_input=None):
|
||||||
"""Install OpenZWave add-on."""
|
"""Install OpenZWave add-on."""
|
||||||
|
if not self.install_task:
|
||||||
|
self.install_task = self.hass.async_create_task(self._async_install_addon())
|
||||||
|
return self.async_show_progress(
|
||||||
|
step_id="install_addon", progress_action="install_addon"
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.hass.components.hassio.async_install_addon("core_zwave")
|
await self.install_task
|
||||||
except self.hass.components.hassio.HassioAPIError as err:
|
except self.hass.components.hassio.HassioAPIError as err:
|
||||||
_LOGGER.error("Failed to install OpenZWave add-on: %s", err)
|
_LOGGER.error("Failed to install OpenZWave add-on: %s", err)
|
||||||
return self.async_abort(reason="addon_install_failed")
|
return self.async_show_progress_done(next_step_id="install_failed")
|
||||||
|
|
||||||
self.integration_created_addon = True
|
self.integration_created_addon = True
|
||||||
|
|
||||||
return await self.async_step_start_addon()
|
return self.async_show_progress_done(next_step_id="start_addon")
|
||||||
|
|
||||||
|
async def async_step_install_failed(self, user_input=None):
|
||||||
|
"""Add-on installation failed."""
|
||||||
|
return self.async_abort(reason="addon_install_failed")
|
||||||
|
|
||||||
async def async_step_start_addon(self, user_input=None):
|
async def async_step_start_addon(self, user_input=None):
|
||||||
"""Ask for config and start OpenZWave add-on."""
|
"""Ask for config and start OpenZWave add-on."""
|
||||||
|
@ -181,3 +193,13 @@ class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
except self.hass.components.hassio.HassioAPIError as err:
|
except self.hass.components.hassio.HassioAPIError as err:
|
||||||
_LOGGER.error("Failed to set OpenZWave add-on config: %s", err)
|
_LOGGER.error("Failed to set OpenZWave add-on config: %s", err)
|
||||||
raise AbortFlow("addon_set_config_failed") from err
|
raise AbortFlow("addon_set_config_failed") from err
|
||||||
|
|
||||||
|
async def _async_install_addon(self):
|
||||||
|
"""Install the OpenZWave add-on."""
|
||||||
|
try:
|
||||||
|
await self.hass.components.hassio.async_install_addon("core_zwave")
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
"description": "Do you want to use the OpenZWave Supervisor add-on?",
|
"description": "Do you want to use the OpenZWave Supervisor add-on?",
|
||||||
"data": {"use_addon": "Use the OpenZWave Supervisor add-on"}
|
"data": {"use_addon": "Use the OpenZWave Supervisor add-on"}
|
||||||
},
|
},
|
||||||
|
"install_addon": {
|
||||||
|
"title": "The OpenZWave add-on installation has started"
|
||||||
|
},
|
||||||
"start_addon": {
|
"start_addon": {
|
||||||
"title": "Enter the OpenZWave add-on configuration",
|
"title": "Enter the OpenZWave add-on configuration",
|
||||||
"data": {"usb_path": "[%key:common::config_flow::data::usb_path%]", "network_key": "Network Key"}
|
"data": {"usb_path": "[%key:common::config_flow::data::usb_path%]", "network_key": "Network Key"}
|
||||||
|
@ -20,6 +23,9 @@
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"addon_start_failed": "Failed to start the OpenZWave add-on. Check the configuration."
|
"addon_start_failed": "Failed to start the OpenZWave add-on. Check the configuration."
|
||||||
|
},
|
||||||
|
"progress": {
|
||||||
|
"install_addon": "Please wait while the OpenZWave add-on installation finishes. This can take several minutes."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,13 @@
|
||||||
"error": {
|
"error": {
|
||||||
"addon_start_failed": "Failed to start the OpenZWave add-on. Check the configuration."
|
"addon_start_failed": "Failed to start the OpenZWave add-on. Check the configuration."
|
||||||
},
|
},
|
||||||
|
"progress": {
|
||||||
|
"install_addon": "Please wait while the OpenZWave add-on installation finishes. This can take several minutes."
|
||||||
|
},
|
||||||
"step": {
|
"step": {
|
||||||
|
"install_addon": {
|
||||||
|
"title": "The OpenZWave add-on installation has started"
|
||||||
|
},
|
||||||
"on_supervisor": {
|
"on_supervisor": {
|
||||||
"data": {
|
"data": {
|
||||||
"use_addon": "Use the OpenZWave Supervisor add-on"
|
"use_addon": "Use the OpenZWave Supervisor add-on"
|
||||||
|
|
|
@ -305,6 +305,16 @@ async def test_addon_not_installed(
|
||||||
result["flow_id"], {"use_addon": True}
|
result["flow_id"], {"use_addon": True}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert result["type"] == "progress"
|
||||||
|
|
||||||
|
# Make sure the flow continues when the progress task is done.
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["step_id"] == "start_addon"
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ozw.async_setup", return_value=True
|
"homeassistant.components.ozw.async_setup", return_value=True
|
||||||
) as mock_setup, patch(
|
) as mock_setup, patch(
|
||||||
|
@ -342,5 +352,12 @@ async def test_install_addon_failure(hass, supervisor, addon_installed, install_
|
||||||
result["flow_id"], {"use_addon": True}
|
result["flow_id"], {"use_addon": True}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert result["type"] == "progress"
|
||||||
|
|
||||||
|
# Make sure the flow continues when the progress task is done.
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
assert result["reason"] == "addon_install_failed"
|
assert result["reason"] == "addon_install_failed"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue