Handle single_instance_allowed centrally (#181143)

This commit is contained in:
Josef Zweck
2026-09-03 16:22:09 +02:00
committed by GitHub
parent 5a80328b1d
commit 0ee2592709
60 changed files with 137 additions and 136 deletions
+22
View File
@@ -77,6 +77,7 @@ async def test_single_entry_allowed(
assert result["type"] is data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
assert result["translation_domain"] == HOMEASSISTANT_DOMAIN
async def test_user_no_devices_found(
@@ -152,6 +153,7 @@ async def test_user_has_confirmation_async_discovery_flow(
[
config_entries.SOURCE_BLUETOOTH,
config_entries.SOURCE_DISCOVERY,
config_entries.SOURCE_HOMEKIT,
config_entries.SOURCE_MQTT,
config_entries.SOURCE_SSDP,
config_entries.SOURCE_ZEROCONF,
@@ -171,6 +173,23 @@ async def test_discovery_single_instance(
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
assert result["translation_domain"] == HOMEASSISTANT_DOMAIN
async def test_discovery_confirm_single_instance(
hass: HomeAssistant, discovery_flow_conf: dict[str, bool]
) -> None:
"""Test confirming a discovery aborts once an entry exists."""
flow = config_entries.HANDLERS["test"]()
flow.hass = hass
flow.context = {"source": config_entries.SOURCE_DISCOVERY}
MockConfigEntry(domain="test").add_to_hass(hass)
result = await flow.async_step_confirm({})
assert result["type"] is data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
assert result["translation_domain"] == HOMEASSISTANT_DOMAIN
@pytest.mark.parametrize(
@@ -322,6 +341,8 @@ async def test_import_single_instance(
result = await flow.async_step_import(None)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
assert result["translation_domain"] == HOMEASSISTANT_DOMAIN
async def test_ignored_discoveries(
@@ -370,6 +391,7 @@ async def test_webhook_single_entry_allowed(
assert result["type"] is data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
assert result["translation_domain"] == HOMEASSISTANT_DOMAIN
async def test_webhook_multiple_entries_allowed(