mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Fix HomeWizard setup flow giving error already_in_progress when trying to manually setup already discovered device (#177458)
This commit is contained in:
@@ -19,7 +19,7 @@ from homewizard_energy.models import Device
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import onboarding
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import SOURCE_USER, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import AbortFlow
|
||||
@@ -60,7 +60,8 @@ class HomeWizardConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return await self.async_step_authorize()
|
||||
else:
|
||||
await self.async_set_unique_id(
|
||||
f"{device_info.product_type}_{device_info.serial}"
|
||||
f"{device_info.product_type}_{device_info.serial}",
|
||||
raise_on_progress=False,
|
||||
)
|
||||
self._abort_if_unique_id_configured(updates=user_input)
|
||||
return self.async_create_entry(
|
||||
@@ -110,7 +111,8 @@ class HomeWizardConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
}
|
||||
|
||||
await self.async_set_unique_id(
|
||||
f"{device_info.product_type}_{device_info.serial}"
|
||||
f"{device_info.product_type}_{device_info.serial}",
|
||||
raise_on_progress=self.source != SOURCE_USER,
|
||||
)
|
||||
self._abort_if_unique_id_configured(updates=data)
|
||||
return self.async_create_entry(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
|
||||
"device_not_supported": "This device is not supported",
|
||||
"invalid_discovery_parameters": "Invalid discovery parameters",
|
||||
"reauth_enable_api_successful": "Enabling API was successful",
|
||||
|
||||
@@ -379,6 +379,49 @@ async def test_discovery_flow_updates_new_ip(
|
||||
assert mock_config_entry.data[CONF_IP_ADDRESS] == "1.0.0.127"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_homewizardenergy", "mock_setup_entry")
|
||||
async def test_manual_flow_ignores_pending_discovery_for_same_device(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test the user flow is not blocked by a stale discovery flow for the same device."""
|
||||
discovery_result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=ZeroconfServiceInfo(
|
||||
ip_address=ip_address("1.0.0.127"),
|
||||
ip_addresses=[ip_address("1.0.0.127")],
|
||||
port=80,
|
||||
hostname="p1meter-ddeeff.local.",
|
||||
type="",
|
||||
name="",
|
||||
properties={
|
||||
"api_enabled": "1",
|
||||
"path": "/api/v1",
|
||||
"product_name": "P1 Meter",
|
||||
"product_type": "HWE-P1",
|
||||
"serial": "5c2fafabcdef",
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
assert discovery_result["type"] is FlowResultType.FORM
|
||||
assert discovery_result["step_id"] == "discovery_confirm"
|
||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {CONF_IP_ADDRESS: "2.2.2.2"}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"][CONF_IP_ADDRESS] == "2.2.2.2"
|
||||
|
||||
# The stale discovery flow is cleaned up once the manual flow succeeds
|
||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "reason"),
|
||||
|
||||
Reference in New Issue
Block a user