mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Handle stale ozw discovery flow (#43939)
This commit is contained in:
parent
a47cf27ed6
commit
e23dc90bac
@ -58,17 +58,14 @@ class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
await self.async_set_unique_id(DOMAIN)
|
await self.async_set_unique_id(DOMAIN)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
addon_config = await self._async_get_addon_config()
|
|
||||||
self.usb_path = addon_config[CONF_ADDON_DEVICE]
|
|
||||||
self.network_key = addon_config.get(CONF_ADDON_NETWORK_KEY, "")
|
|
||||||
|
|
||||||
return await self.async_step_hassio_confirm()
|
return await self.async_step_hassio_confirm()
|
||||||
|
|
||||||
async def async_step_hassio_confirm(self, user_input=None):
|
async def async_step_hassio_confirm(self, user_input=None):
|
||||||
"""Confirm the add-on discovery."""
|
"""Confirm the add-on discovery."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self.use_addon = True
|
return await self.async_step_on_supervisor(
|
||||||
return self._async_create_entry_from_vars()
|
user_input={CONF_USE_ADDON: True}
|
||||||
|
)
|
||||||
|
|
||||||
return self.async_show_form(step_id="hassio_confirm")
|
return self.async_show_form(step_id="hassio_confirm")
|
||||||
|
|
||||||
@ -107,6 +104,9 @@ class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self.use_addon = True
|
self.use_addon = True
|
||||||
|
|
||||||
if await self._async_is_addon_running():
|
if await self._async_is_addon_running():
|
||||||
|
addon_config = await self._async_get_addon_config()
|
||||||
|
self.usb_path = addon_config[CONF_ADDON_DEVICE]
|
||||||
|
self.network_key = addon_config.get(CONF_ADDON_NETWORK_KEY, "")
|
||||||
return self._async_create_entry_from_vars()
|
return self._async_create_entry_from_vars()
|
||||||
|
|
||||||
if await self._async_is_addon_installed():
|
if await self._async_is_addon_installed():
|
||||||
|
@ -159,9 +159,10 @@ async def test_not_addon(hass, supervisor):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_addon_running(hass, supervisor, addon_running):
|
async def test_addon_running(hass, supervisor, addon_running, addon_options):
|
||||||
"""Test add-on already running on Supervisor."""
|
"""Test add-on already running on Supervisor."""
|
||||||
hass.config.components.add("mqtt")
|
addon_options["device"] = "/test"
|
||||||
|
addon_options["network_key"] = "abc123"
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -182,8 +183,8 @@ async def test_addon_running(hass, supervisor, addon_running):
|
|||||||
assert result["type"] == "create_entry"
|
assert result["type"] == "create_entry"
|
||||||
assert result["title"] == TITLE
|
assert result["title"] == TITLE
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
"usb_path": None,
|
"usb_path": "/test",
|
||||||
"network_key": None,
|
"network_key": "abc123",
|
||||||
"use_addon": True,
|
"use_addon": True,
|
||||||
"integration_created_addon": False,
|
"integration_created_addon": False,
|
||||||
}
|
}
|
||||||
@ -193,7 +194,6 @@ async def test_addon_running(hass, supervisor, addon_running):
|
|||||||
|
|
||||||
async def test_addon_info_failure(hass, supervisor, addon_info):
|
async def test_addon_info_failure(hass, supervisor, addon_info):
|
||||||
"""Test add-on info failure."""
|
"""Test add-on info failure."""
|
||||||
hass.config.components.add("mqtt")
|
|
||||||
addon_info.side_effect = HassioAPIError()
|
addon_info.side_effect = HassioAPIError()
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
@ -213,7 +213,6 @@ async def test_addon_installed(
|
|||||||
hass, supervisor, addon_installed, addon_options, set_addon_options, start_addon
|
hass, supervisor, addon_installed, addon_options, set_addon_options, start_addon
|
||||||
):
|
):
|
||||||
"""Test add-on already installed but not running on Supervisor."""
|
"""Test add-on already installed but not running on Supervisor."""
|
||||||
hass.config.components.add("mqtt")
|
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -250,7 +249,6 @@ async def test_set_addon_config_failure(
|
|||||||
hass, supervisor, addon_installed, addon_options, set_addon_options
|
hass, supervisor, addon_installed, addon_options, set_addon_options
|
||||||
):
|
):
|
||||||
"""Test add-on set config failure."""
|
"""Test add-on set config failure."""
|
||||||
hass.config.components.add("mqtt")
|
|
||||||
set_addon_options.side_effect = HassioAPIError()
|
set_addon_options.side_effect = HassioAPIError()
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
@ -273,7 +271,6 @@ async def test_start_addon_failure(
|
|||||||
hass, supervisor, addon_installed, addon_options, set_addon_options, start_addon
|
hass, supervisor, addon_installed, addon_options, set_addon_options, start_addon
|
||||||
):
|
):
|
||||||
"""Test add-on start failure."""
|
"""Test add-on start failure."""
|
||||||
hass.config.components.add("mqtt")
|
|
||||||
start_addon.side_effect = HassioAPIError()
|
start_addon.side_effect = HassioAPIError()
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
@ -302,7 +299,6 @@ async def test_addon_not_installed(
|
|||||||
start_addon,
|
start_addon,
|
||||||
):
|
):
|
||||||
"""Test add-on not installed."""
|
"""Test add-on not installed."""
|
||||||
hass.config.components.add("mqtt")
|
|
||||||
addon_installed.return_value["version"] = None
|
addon_installed.return_value["version"] = None
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
@ -348,7 +344,6 @@ async def test_addon_not_installed(
|
|||||||
|
|
||||||
async def test_install_addon_failure(hass, supervisor, addon_installed, install_addon):
|
async def test_install_addon_failure(hass, supervisor, addon_installed, install_addon):
|
||||||
"""Test add-on install failure."""
|
"""Test add-on install failure."""
|
||||||
hass.config.components.add("mqtt")
|
|
||||||
addon_installed.return_value["version"] = None
|
addon_installed.return_value["version"] = None
|
||||||
install_addon.side_effect = HassioAPIError()
|
install_addon.side_effect = HassioAPIError()
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
@ -488,3 +483,54 @@ async def test_abort_discovery_with_existing_entry(
|
|||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_addon_not_running(
|
||||||
|
hass, supervisor, addon_installed, addon_options, set_addon_options, start_addon
|
||||||
|
):
|
||||||
|
"""Test discovery with add-on already installed but not running."""
|
||||||
|
addon_options["device"] = None
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_HASSIO},
|
||||||
|
data=ADDON_DISCOVERY_INFO,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["step_id"] == "hassio_confirm"
|
||||||
|
assert result["type"] == "form"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||||
|
|
||||||
|
assert result["step_id"] == "start_addon"
|
||||||
|
assert result["type"] == "form"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_addon_not_installed(
|
||||||
|
hass, supervisor, addon_installed, install_addon, addon_options
|
||||||
|
):
|
||||||
|
"""Test discovery with add-on not installed."""
|
||||||
|
addon_installed.return_value["version"] = None
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_HASSIO},
|
||||||
|
data=ADDON_DISCOVERY_INFO,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["step_id"] == "hassio_confirm"
|
||||||
|
assert result["type"] == "form"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||||
|
|
||||||
|
assert result["step_id"] == "install_addon"
|
||||||
|
assert result["type"] == "progress"
|
||||||
|
|
||||||
|
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user