mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
ConfigSubEntryFlow _get_reconfigure_entry() -> _get_entry() (#141017)
* ConfigSubEntryFlow _get_reconfigure_entry() -> _get_entry() * Update MQTT test * Fix test_config_entries * Minimize changes to keep existing tests working * Re-revert and update negative test instead
This commit is contained in:
parent
0514de3e16
commit
d65392a374
@ -147,7 +147,7 @@ class SubentryFlowHandler(ConfigSubentryFlow):
|
||||
if user_input is not None:
|
||||
title = user_input.pop("name")
|
||||
return self.async_update_and_abort(
|
||||
self._get_reconfigure_entry(),
|
||||
self._get_entry(),
|
||||
self._get_reconfigure_subentry(),
|
||||
data=user_input,
|
||||
title=title,
|
||||
|
@ -1176,7 +1176,7 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> SubentryFlowResult:
|
||||
"""Save the changes made to the subentry."""
|
||||
entry = self._get_reconfigure_entry()
|
||||
entry = self._get_entry()
|
||||
subentry = self._get_reconfigure_subentry()
|
||||
entity_registry = er.async_get(self.hass)
|
||||
|
||||
|
@ -3491,18 +3491,14 @@ class ConfigSubentryFlow(
|
||||
return self.async_abort(reason="reconfigure_successful")
|
||||
|
||||
@property
|
||||
def _reconfigure_entry_id(self) -> str:
|
||||
"""Return reconfigure entry id."""
|
||||
if self.source != SOURCE_RECONFIGURE:
|
||||
raise ValueError(f"Source is {self.source}, expected {SOURCE_RECONFIGURE}")
|
||||
def _entry_id(self) -> str:
|
||||
"""Return config entry id."""
|
||||
return self.handler[0]
|
||||
|
||||
@callback
|
||||
def _get_reconfigure_entry(self) -> ConfigEntry:
|
||||
"""Return the reconfigure config entry linked to the current context."""
|
||||
return self.hass.config_entries.async_get_known_entry(
|
||||
self._reconfigure_entry_id
|
||||
)
|
||||
def _get_entry(self) -> ConfigEntry:
|
||||
"""Return the config entry linked to the current context."""
|
||||
return self.hass.config_entries.async_get_known_entry(self._entry_id)
|
||||
|
||||
@property
|
||||
def _reconfigure_subentry_id(self) -> str:
|
||||
@ -3514,9 +3510,7 @@ class ConfigSubentryFlow(
|
||||
@callback
|
||||
def _get_reconfigure_subentry(self) -> ConfigSubentry:
|
||||
"""Return the reconfigure config subentry linked to the current context."""
|
||||
entry = self.hass.config_entries.async_get_known_entry(
|
||||
self._reconfigure_entry_id
|
||||
)
|
||||
entry = self.hass.config_entries.async_get_known_entry(self._entry_id)
|
||||
subentry_id = self._reconfigure_subentry_id
|
||||
if subentry_id not in entry.subentries:
|
||||
raise UnknownSubEntry(subentry_id)
|
||||
|
@ -1193,7 +1193,7 @@ async def test_subentry_reconfigure_flow(hass: HomeAssistant, client) -> None:
|
||||
async def async_step_reconfigure(self, user_input=None):
|
||||
if user_input is not None:
|
||||
return self.async_update_and_abort(
|
||||
self._get_reconfigure_entry(),
|
||||
self._get_entry(),
|
||||
self._get_reconfigure_subentry(),
|
||||
title="Test Entry",
|
||||
data={"test": "blah"},
|
||||
|
@ -6566,7 +6566,7 @@ async def test_update_subentry_and_abort(
|
||||
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||
async def async_step_reconfigure(self, user_input=None):
|
||||
return self.async_update_and_abort(
|
||||
self._get_reconfigure_entry(),
|
||||
self._get_entry(),
|
||||
self._get_reconfigure_subentry(),
|
||||
**kwargs,
|
||||
)
|
||||
@ -8158,10 +8158,10 @@ async def test_get_reconfigure_entry(
|
||||
assert result["reason"] == "Source is user, expected reconfigure: -"
|
||||
|
||||
|
||||
async def test_subentry_get_reconfigure_entry(
|
||||
async def test_subentry_get_entry(
|
||||
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
||||
) -> None:
|
||||
"""Test subentry _get_reconfigure_entry and _get_reconfigure_subentry behavior."""
|
||||
"""Test subentry _get_entry and _get_reconfigure_subentry behavior."""
|
||||
subentry_id = "mock_subentry_id"
|
||||
entry = MockConfigEntry(
|
||||
data={},
|
||||
@ -8198,13 +8198,13 @@ async def test_subentry_get_reconfigure_entry(
|
||||
async def _async_step_confirm(self):
|
||||
"""Confirm input."""
|
||||
try:
|
||||
entry = self._get_reconfigure_entry()
|
||||
entry = self._get_entry()
|
||||
except ValueError as err:
|
||||
reason = str(err)
|
||||
else:
|
||||
reason = f"Found entry {entry.title}"
|
||||
try:
|
||||
entry_id = self._reconfigure_entry_id
|
||||
entry_id = self._entry_id
|
||||
except ValueError:
|
||||
reason = f"{reason}: -"
|
||||
else:
|
||||
@ -8233,7 +8233,7 @@ async def test_subentry_get_reconfigure_entry(
|
||||
) -> dict[str, type[config_entries.ConfigSubentryFlow]]:
|
||||
return {"test": TestFlow.SubentryFlowHandler}
|
||||
|
||||
# A reconfigure flow finds the config entry
|
||||
# A reconfigure flow finds the config entry and subentry
|
||||
with mock_config_flow("test", TestFlow):
|
||||
result = await entry.start_subentry_reconfigure_flow(hass, "test", subentry_id)
|
||||
assert (
|
||||
@ -8255,14 +8255,14 @@ async def test_subentry_get_reconfigure_entry(
|
||||
== "Found entry entry_title: mock_entry_id/Subentry not found: 01JRemoved"
|
||||
)
|
||||
|
||||
# A user flow does not have access to the config entry or subentry
|
||||
# A user flow finds the config entry but not the subentry
|
||||
with mock_config_flow("test", TestFlow):
|
||||
result = await manager.subentries.async_init(
|
||||
(entry.entry_id, "test"), context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert (
|
||||
result["reason"]
|
||||
== "Source is user, expected reconfigure: -/Source is user, expected reconfigure: -"
|
||||
== "Found entry entry_title: mock_entry_id/Source is user, expected reconfigure: -"
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user