Skip to content

Commit d65392a

Browse files
authored
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
1 parent 0514de3 commit d65392a

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

homeassistant/components/kitchen_sink/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def async_step_reconfigure_sensor(
147147
if user_input is not None:
148148
title = user_input.pop("name")
149149
return self.async_update_and_abort(
150-
self._get_reconfigure_entry(),
150+
self._get_entry(),
151151
self._get_reconfigure_subentry(),
152152
data=user_input,
153153
title=title,

homeassistant/components/mqtt/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ async def async_step_save_changes(
11761176
self, user_input: dict[str, Any] | None = None
11771177
) -> SubentryFlowResult:
11781178
"""Save the changes made to the subentry."""
1179-
entry = self._get_reconfigure_entry()
1179+
entry = self._get_entry()
11801180
subentry = self._get_reconfigure_subentry()
11811181
entity_registry = er.async_get(self.hass)
11821182

homeassistant/config_entries.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,18 +3491,14 @@ def async_update_and_abort(
34913491
return self.async_abort(reason="reconfigure_successful")
34923492

34933493
@property
3494-
def _reconfigure_entry_id(self) -> str:
3495-
"""Return reconfigure entry id."""
3496-
if self.source != SOURCE_RECONFIGURE:
3497-
raise ValueError(f"Source is {self.source}, expected {SOURCE_RECONFIGURE}")
3494+
def _entry_id(self) -> str:
3495+
"""Return config entry id."""
34983496
return self.handler[0]
34993497

35003498
@callback
3501-
def _get_reconfigure_entry(self) -> ConfigEntry:
3502-
"""Return the reconfigure config entry linked to the current context."""
3503-
return self.hass.config_entries.async_get_known_entry(
3504-
self._reconfigure_entry_id
3505-
)
3499+
def _get_entry(self) -> ConfigEntry:
3500+
"""Return the config entry linked to the current context."""
3501+
return self.hass.config_entries.async_get_known_entry(self._entry_id)
35063502

35073503
@property
35083504
def _reconfigure_subentry_id(self) -> str:
@@ -3514,9 +3510,7 @@ def _reconfigure_subentry_id(self) -> str:
35143510
@callback
35153511
def _get_reconfigure_subentry(self) -> ConfigSubentry:
35163512
"""Return the reconfigure config subentry linked to the current context."""
3517-
entry = self.hass.config_entries.async_get_known_entry(
3518-
self._reconfigure_entry_id
3519-
)
3513+
entry = self.hass.config_entries.async_get_known_entry(self._entry_id)
35203514
subentry_id = self._reconfigure_subentry_id
35213515
if subentry_id not in entry.subentries:
35223516
raise UnknownSubEntry(subentry_id)

tests/components/config/test_config_entries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ async def async_step_user(self, user_input=None):
11931193
async def async_step_reconfigure(self, user_input=None):
11941194
if user_input is not None:
11951195
return self.async_update_and_abort(
1196-
self._get_reconfigure_entry(),
1196+
self._get_entry(),
11971197
self._get_reconfigure_subentry(),
11981198
title="Test Entry",
11991199
data={"test": "blah"},

tests/test_config_entries.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6566,7 +6566,7 @@ class TestFlow(config_entries.ConfigFlow):
65666566
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
65676567
async def async_step_reconfigure(self, user_input=None):
65686568
return self.async_update_and_abort(
6569-
self._get_reconfigure_entry(),
6569+
self._get_entry(),
65706570
self._get_reconfigure_subentry(),
65716571
**kwargs,
65726572
)
@@ -8158,10 +8158,10 @@ async def _async_step_confirm(self):
81588158
assert result["reason"] == "Source is user, expected reconfigure: -"
81598159

81608160

8161-
async def test_subentry_get_reconfigure_entry(
8161+
async def test_subentry_get_entry(
81628162
hass: HomeAssistant, manager: config_entries.ConfigEntries
81638163
) -> None:
8164-
"""Test subentry _get_reconfigure_entry and _get_reconfigure_subentry behavior."""
8164+
"""Test subentry _get_entry and _get_reconfigure_subentry behavior."""
81658165
subentry_id = "mock_subentry_id"
81668166
entry = MockConfigEntry(
81678167
data={},
@@ -8198,13 +8198,13 @@ async def async_step_reconfigure(self, user_input=None):
81988198
async def _async_step_confirm(self):
81998199
"""Confirm input."""
82008200
try:
8201-
entry = self._get_reconfigure_entry()
8201+
entry = self._get_entry()
82028202
except ValueError as err:
82038203
reason = str(err)
82048204
else:
82058205
reason = f"Found entry {entry.title}"
82068206
try:
8207-
entry_id = self._reconfigure_entry_id
8207+
entry_id = self._entry_id
82088208
except ValueError:
82098209
reason = f"{reason}: -"
82108210
else:
@@ -8233,7 +8233,7 @@ def async_get_supported_subentry_types(
82338233
) -> dict[str, type[config_entries.ConfigSubentryFlow]]:
82348234
return {"test": TestFlow.SubentryFlowHandler}
82358235

8236-
# A reconfigure flow finds the config entry
8236+
# A reconfigure flow finds the config entry and subentry
82378237
with mock_config_flow("test", TestFlow):
82388238
result = await entry.start_subentry_reconfigure_flow(hass, "test", subentry_id)
82398239
assert (
@@ -8255,14 +8255,14 @@ def async_get_supported_subentry_types(
82558255
== "Found entry entry_title: mock_entry_id/Subentry not found: 01JRemoved"
82568256
)
82578257

8258-
# A user flow does not have access to the config entry or subentry
8258+
# A user flow finds the config entry but not the subentry
82598259
with mock_config_flow("test", TestFlow):
82608260
result = await manager.subentries.async_init(
82618261
(entry.entry_id, "test"), context={"source": config_entries.SOURCE_USER}
82628262
)
82638263
assert (
82648264
result["reason"]
8265-
== "Source is user, expected reconfigure: -/Source is user, expected reconfigure: -"
8265+
== "Found entry entry_title: mock_entry_id/Source is user, expected reconfigure: -"
82668266
)
82678267

82688268

0 commit comments

Comments
 (0)