Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions homeassistant/components/ozw/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):
self.use_addon = False
# If we install the add-on we should uninstall it on entry remove.
self.integration_created_addon = False
self.install_task = None

async def async_step_user(self, user_input=None):
"""Handle the initial step."""
Expand Down Expand Up @@ -93,16 +94,27 @@ async def async_step_on_supervisor(self, user_input=None):

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."""
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:
await self.hass.components.hassio.async_install_addon("core_zwave")
await self.install_task
except self.hass.components.hassio.HassioAPIError as 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

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):
"""Ask for config and start OpenZWave add-on."""
Expand Down Expand Up @@ -181,3 +193,13 @@ async def _async_set_addon_config(self, config):
except self.hass.components.hassio.HassioAPIError as err:
_LOGGER.error("Failed to set OpenZWave add-on config: %s", 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 changes: 6 additions & 0 deletions homeassistant/components/ozw/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"description": "Do you want to 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": {
"title": "Enter the OpenZWave add-on configuration",
"data": {"usb_path": "[%key:common::config_flow::data::usb_path%]", "network_key": "Network Key"}
Expand All @@ -20,6 +23,9 @@
},
"error": {
"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."
}
}
}
6 changes: 6 additions & 0 deletions homeassistant/components/ozw/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"error": {
"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": {
"install_addon": {
"title": "The OpenZWave add-on installation has started"
},
"on_supervisor": {
"data": {
"use_addon": "Use the OpenZWave Supervisor add-on"
Expand Down
17 changes: 17 additions & 0 deletions tests/components/ozw/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ async def test_addon_not_installed(
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(
"homeassistant.components.ozw.async_setup", return_value=True
) as mock_setup, patch(
Expand Down Expand Up @@ -342,5 +352,12 @@ async def test_install_addon_failure(hass, supervisor, addon_installed, install_
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["reason"] == "addon_install_failed"