mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +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:
|
if user_input is not None:
|
||||||
title = user_input.pop("name")
|
title = user_input.pop("name")
|
||||||
return self.async_update_and_abort(
|
return self.async_update_and_abort(
|
||||||
self._get_reconfigure_entry(),
|
self._get_entry(),
|
||||||
self._get_reconfigure_subentry(),
|
self._get_reconfigure_subentry(),
|
||||||
data=user_input,
|
data=user_input,
|
||||||
title=title,
|
title=title,
|
||||||
|
@ -1176,7 +1176,7 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> SubentryFlowResult:
|
) -> SubentryFlowResult:
|
||||||
"""Save the changes made to the subentry."""
|
"""Save the changes made to the subentry."""
|
||||||
entry = self._get_reconfigure_entry()
|
entry = self._get_entry()
|
||||||
subentry = self._get_reconfigure_subentry()
|
subentry = self._get_reconfigure_subentry()
|
||||||
entity_registry = er.async_get(self.hass)
|
entity_registry = er.async_get(self.hass)
|
||||||
|
|
||||||
|
@ -3491,18 +3491,14 @@ class ConfigSubentryFlow(
|
|||||||
return self.async_abort(reason="reconfigure_successful")
|
return self.async_abort(reason="reconfigure_successful")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _reconfigure_entry_id(self) -> str:
|
def _entry_id(self) -> str:
|
||||||
"""Return reconfigure entry id."""
|
"""Return config entry id."""
|
||||||
if self.source != SOURCE_RECONFIGURE:
|
|
||||||
raise ValueError(f"Source is {self.source}, expected {SOURCE_RECONFIGURE}")
|
|
||||||
return self.handler[0]
|
return self.handler[0]
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _get_reconfigure_entry(self) -> ConfigEntry:
|
def _get_entry(self) -> ConfigEntry:
|
||||||
"""Return the reconfigure config entry linked to the current context."""
|
"""Return the config entry linked to the current context."""
|
||||||
return self.hass.config_entries.async_get_known_entry(
|
return self.hass.config_entries.async_get_known_entry(self._entry_id)
|
||||||
self._reconfigure_entry_id
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _reconfigure_subentry_id(self) -> str:
|
def _reconfigure_subentry_id(self) -> str:
|
||||||
@ -3514,9 +3510,7 @@ class ConfigSubentryFlow(
|
|||||||
@callback
|
@callback
|
||||||
def _get_reconfigure_subentry(self) -> ConfigSubentry:
|
def _get_reconfigure_subentry(self) -> ConfigSubentry:
|
||||||
"""Return the reconfigure config subentry linked to the current context."""
|
"""Return the reconfigure config subentry linked to the current context."""
|
||||||
entry = self.hass.config_entries.async_get_known_entry(
|
entry = self.hass.config_entries.async_get_known_entry(self._entry_id)
|
||||||
self._reconfigure_entry_id
|
|
||||||
)
|
|
||||||
subentry_id = self._reconfigure_subentry_id
|
subentry_id = self._reconfigure_subentry_id
|
||||||
if subentry_id not in entry.subentries:
|
if subentry_id not in entry.subentries:
|
||||||
raise UnknownSubEntry(subentry_id)
|
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):
|
async def async_step_reconfigure(self, user_input=None):
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_update_and_abort(
|
return self.async_update_and_abort(
|
||||||
self._get_reconfigure_entry(),
|
self._get_entry(),
|
||||||
self._get_reconfigure_subentry(),
|
self._get_reconfigure_subentry(),
|
||||||
title="Test Entry",
|
title="Test Entry",
|
||||||
data={"test": "blah"},
|
data={"test": "blah"},
|
||||||
|
@ -6566,7 +6566,7 @@ async def test_update_subentry_and_abort(
|
|||||||
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
async def async_step_reconfigure(self, user_input=None):
|
async def async_step_reconfigure(self, user_input=None):
|
||||||
return self.async_update_and_abort(
|
return self.async_update_and_abort(
|
||||||
self._get_reconfigure_entry(),
|
self._get_entry(),
|
||||||
self._get_reconfigure_subentry(),
|
self._get_reconfigure_subentry(),
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
@ -8158,10 +8158,10 @@ async def test_get_reconfigure_entry(
|
|||||||
assert result["reason"] == "Source is user, expected reconfigure: -"
|
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
|
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
||||||
) -> None:
|
) -> 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"
|
subentry_id = "mock_subentry_id"
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
data={},
|
data={},
|
||||||
@ -8198,13 +8198,13 @@ async def test_subentry_get_reconfigure_entry(
|
|||||||
async def _async_step_confirm(self):
|
async def _async_step_confirm(self):
|
||||||
"""Confirm input."""
|
"""Confirm input."""
|
||||||
try:
|
try:
|
||||||
entry = self._get_reconfigure_entry()
|
entry = self._get_entry()
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
reason = str(err)
|
reason = str(err)
|
||||||
else:
|
else:
|
||||||
reason = f"Found entry {entry.title}"
|
reason = f"Found entry {entry.title}"
|
||||||
try:
|
try:
|
||||||
entry_id = self._reconfigure_entry_id
|
entry_id = self._entry_id
|
||||||
except ValueError:
|
except ValueError:
|
||||||
reason = f"{reason}: -"
|
reason = f"{reason}: -"
|
||||||
else:
|
else:
|
||||||
@ -8233,7 +8233,7 @@ async def test_subentry_get_reconfigure_entry(
|
|||||||
) -> dict[str, type[config_entries.ConfigSubentryFlow]]:
|
) -> dict[str, type[config_entries.ConfigSubentryFlow]]:
|
||||||
return {"test": TestFlow.SubentryFlowHandler}
|
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):
|
with mock_config_flow("test", TestFlow):
|
||||||
result = await entry.start_subentry_reconfigure_flow(hass, "test", subentry_id)
|
result = await entry.start_subentry_reconfigure_flow(hass, "test", subentry_id)
|
||||||
assert (
|
assert (
|
||||||
@ -8255,14 +8255,14 @@ async def test_subentry_get_reconfigure_entry(
|
|||||||
== "Found entry entry_title: mock_entry_id/Subentry not found: 01JRemoved"
|
== "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):
|
with mock_config_flow("test", TestFlow):
|
||||||
result = await manager.subentries.async_init(
|
result = await manager.subentries.async_init(
|
||||||
(entry.entry_id, "test"), context={"source": config_entries.SOURCE_USER}
|
(entry.entry_id, "test"), context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
result["reason"]
|
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