mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Remove dead reconfigure code (#127398)
* Remove dead reconfigure code * Adjust * Start cleaning up test * Prevent duplicate flows * Add missing string * Adjust two more tests * Only filter out reauth flows * Update strings.json * Update config_entries.py * Adjust tests * Remove all checks - but add comment in tests * Simplify PR
This commit is contained in:
parent
b56e22d4ee
commit
4478f64002
@ -326,7 +326,6 @@ class ConfigEntry(Generic[_DataT]):
|
|||||||
_on_unload: list[Callable[[], Coroutine[Any, Any, None] | None]] | None
|
_on_unload: list[Callable[[], Coroutine[Any, Any, None] | None]] | None
|
||||||
setup_lock: asyncio.Lock
|
setup_lock: asyncio.Lock
|
||||||
_reauth_lock: asyncio.Lock
|
_reauth_lock: asyncio.Lock
|
||||||
_reconfigure_lock: asyncio.Lock
|
|
||||||
_tasks: set[asyncio.Future[Any]]
|
_tasks: set[asyncio.Future[Any]]
|
||||||
_background_tasks: set[asyncio.Future[Any]]
|
_background_tasks: set[asyncio.Future[Any]]
|
||||||
_integration_for_domain: loader.Integration | None
|
_integration_for_domain: loader.Integration | None
|
||||||
@ -430,8 +429,6 @@ class ConfigEntry(Generic[_DataT]):
|
|||||||
_setter(self, "setup_lock", asyncio.Lock())
|
_setter(self, "setup_lock", asyncio.Lock())
|
||||||
# Reauth lock to prevent concurrent reauth flows
|
# Reauth lock to prevent concurrent reauth flows
|
||||||
_setter(self, "_reauth_lock", asyncio.Lock())
|
_setter(self, "_reauth_lock", asyncio.Lock())
|
||||||
# Reconfigure lock to prevent concurrent reconfigure flows
|
|
||||||
_setter(self, "_reconfigure_lock", asyncio.Lock())
|
|
||||||
|
|
||||||
_setter(self, "_tasks", set())
|
_setter(self, "_tasks", set())
|
||||||
_setter(self, "_background_tasks", set())
|
_setter(self, "_background_tasks", set())
|
||||||
@ -1094,49 +1091,6 @@ class ConfigEntry(Generic[_DataT]):
|
|||||||
translation_placeholders={"name": self.title},
|
translation_placeholders={"name": self.title},
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_start_reconfigure(
|
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
context: ConfigFlowContext | None = None,
|
|
||||||
data: dict[str, Any] | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Start a reconfigure flow."""
|
|
||||||
# We will check this again in the task when we hold the lock,
|
|
||||||
# but we also check it now to try to avoid creating the task.
|
|
||||||
if any(self.async_get_active_flows(hass, {SOURCE_RECONFIGURE, SOURCE_REAUTH})):
|
|
||||||
# Reconfigure or reauth flow already in progress for this entry
|
|
||||||
return
|
|
||||||
hass.async_create_task(
|
|
||||||
self._async_init_reconfigure(hass, context, data),
|
|
||||||
f"config entry reconfigure {self.title} {self.domain} {self.entry_id}",
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _async_init_reconfigure(
|
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
context: ConfigFlowContext | None = None,
|
|
||||||
data: dict[str, Any] | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Start a reconfigure flow."""
|
|
||||||
async with self._reconfigure_lock:
|
|
||||||
if any(
|
|
||||||
self.async_get_active_flows(hass, {SOURCE_RECONFIGURE, SOURCE_REAUTH})
|
|
||||||
):
|
|
||||||
# Reconfigure or reauth flow already in progress for this entry
|
|
||||||
return
|
|
||||||
await hass.config_entries.flow.async_init(
|
|
||||||
self.domain,
|
|
||||||
context=ConfigFlowContext(
|
|
||||||
source=SOURCE_RECONFIGURE,
|
|
||||||
entry_id=self.entry_id,
|
|
||||||
title_placeholders={"name": self.title},
|
|
||||||
unique_id=self.unique_id,
|
|
||||||
)
|
|
||||||
| (context or {}),
|
|
||||||
data=self.data | (data or {}),
|
|
||||||
)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_get_active_flows(
|
def async_get_active_flows(
|
||||||
self, hass: HomeAssistant, sources: set[str]
|
self, hass: HomeAssistant, sources: set[str]
|
||||||
|
@ -989,7 +989,6 @@ async def test_as_dict(snapshot: SnapshotAssertion) -> None:
|
|||||||
"_tries",
|
"_tries",
|
||||||
"_setup_again_job",
|
"_setup_again_job",
|
||||||
"_supports_options",
|
"_supports_options",
|
||||||
"_reconfigure_lock",
|
|
||||||
"supports_reconfigure",
|
"supports_reconfigure",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4764,38 +4763,67 @@ async def test_reconfigure(
|
|||||||
await manager.async_setup(entry.entry_id)
|
await manager.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
flow = hass.config_entries.flow
|
def _async_start_reconfigure(config_entry: MockConfigEntry) -> None:
|
||||||
with patch.object(flow, "async_init", wraps=flow.async_init) as mock_init:
|
hass.async_create_task(
|
||||||
entry.async_start_reconfigure(
|
manager.flow.async_init(
|
||||||
hass,
|
config_entry.domain,
|
||||||
context={"extra_context": "some_extra_context"},
|
context={
|
||||||
data={"extra_data": 1234},
|
"source": config_entries.SOURCE_RECONFIGURE,
|
||||||
|
"entry_id": config_entry.entry_id,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
f"config entry reconfigure {config_entry.title} "
|
||||||
|
f"{config_entry.domain} {config_entry.entry_id}",
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
flow = hass.config_entries.flow
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
flows = hass.config_entries.flow.async_progress()
|
flows = hass.config_entries.flow.async_progress()
|
||||||
assert len(flows) == 1
|
assert len(flows) == 1
|
||||||
assert flows[0]["context"]["entry_id"] == entry.entry_id
|
assert flows[0]["context"]["entry_id"] == entry.entry_id
|
||||||
assert flows[0]["context"]["source"] == config_entries.SOURCE_RECONFIGURE
|
assert flows[0]["context"]["source"] == config_entries.SOURCE_RECONFIGURE
|
||||||
assert flows[0]["context"]["title_placeholders"] == {"name": "test_title"}
|
|
||||||
assert flows[0]["context"]["extra_context"] == "some_extra_context"
|
|
||||||
|
|
||||||
assert mock_init.call_args.kwargs["data"]["extra_data"] == 1234
|
|
||||||
|
|
||||||
assert entry.entry_id != entry2.entry_id
|
assert entry.entry_id != entry2.entry_id
|
||||||
|
|
||||||
# Check that we can't start duplicate reconfigure flows
|
# Check that we can start duplicate reconfigure flows
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
# (may need revisiting)
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
assert len(hass.config_entries.flow.async_progress()) == 2
|
||||||
|
|
||||||
# Check that we can't start duplicate reconfigure flows when the context is different
|
|
||||||
entry.async_start_reconfigure(hass, {"diff": "diff"})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
|
||||||
|
|
||||||
# Check that we can start a reconfigure flow for a different entry
|
# Check that we can start a reconfigure flow for a different entry
|
||||||
entry2.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
_async_start_reconfigure(entry2)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(hass.config_entries.flow.async_progress()) == 3
|
||||||
|
|
||||||
|
# Abort all existing flows
|
||||||
|
for flow in hass.config_entries.flow.async_progress():
|
||||||
|
hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Check that we can start duplicate reconfigure flows
|
||||||
|
# without blocking between flows
|
||||||
|
# (may need revisiting)
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(hass.config_entries.flow.async_progress()) == 4
|
||||||
|
|
||||||
|
# Abort all existing flows
|
||||||
|
for flow in hass.config_entries.flow.async_progress():
|
||||||
|
hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Check that we can start reconfigure flows with active reauth flow
|
||||||
|
# (may need revisiting)
|
||||||
|
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||||
|
_async_start_reconfigure(entry)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 2
|
assert len(hass.config_entries.flow.async_progress()) == 2
|
||||||
|
|
||||||
@ -4804,35 +4832,8 @@ async def test_reconfigure(
|
|||||||
hass.config_entries.flow.async_abort(flow["flow_id"])
|
hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Check that we can't start duplicate reconfigure flows
|
|
||||||
# without blocking between flows
|
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
|
||||||
|
|
||||||
# Abort all existing flows
|
|
||||||
for flow in hass.config_entries.flow.async_progress():
|
|
||||||
hass.config_entries.flow.async_abort(flow["flow_id"])
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Check that we can't start reconfigure flows with active reauth flow
|
|
||||||
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
|
||||||
|
|
||||||
# Abort all existing flows
|
|
||||||
for flow in hass.config_entries.flow.async_progress():
|
|
||||||
hass.config_entries.flow.async_abort(flow["flow_id"])
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Check that we can't start reauth flows with active reconfigure flow
|
# Check that we can't start reauth flows with active reconfigure flow
|
||||||
entry.async_start_reconfigure(hass, {"extra_context": "some_extra_context"})
|
_async_start_reconfigure(entry)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||||
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
|
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user