Add test of ConfigSubentryFlow._subentry_type (#147565)

This commit is contained in:
Erik Montnemery 2025-07-26 00:27:04 +02:00 committed by GitHub
parent cbf4409db3
commit aab7381553
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8008,7 +8008,10 @@ async def test_get_reconfigure_entry(
async def test_subentry_get_entry( async def test_subentry_get_entry(
hass: HomeAssistant, manager: config_entries.ConfigEntries hass: HomeAssistant, manager: config_entries.ConfigEntries
) -> None: ) -> None:
"""Test subentry _get_entry and _get_reconfigure_subentry behavior.""" """Test subentry _get_entry and _get_reconfigure_subentry behavior.
Also tests related helpers _entry_id, _subentry_type, _reconfigure_subentry_id
"""
subentry_id = "mock_subentry_id" subentry_id = "mock_subentry_id"
entry = MockConfigEntry( entry = MockConfigEntry(
data={}, data={},
@ -8044,18 +8047,8 @@ async def test_subentry_get_entry(
async def _async_step_confirm(self): async def _async_step_confirm(self):
"""Confirm input.""" """Confirm input."""
try: reason = f"Found entry {self._get_entry().title},{self._entry_id}: "
entry = self._get_entry() reason = f"{reason}subentry_type={self._subentry_type}"
except ValueError as err:
reason = str(err)
else:
reason = f"Found entry {entry.title}"
try:
entry_id = self._entry_id
except ValueError:
reason = f"{reason}: -"
else:
reason = f"{reason}: {entry_id}"
try: try:
subentry = self._get_reconfigure_subentry() subentry = self._get_reconfigure_subentry()
@ -8083,9 +8076,9 @@ async def test_subentry_get_entry(
# A reconfigure flow finds the config entry and subentry # 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, subentry_id) result = await entry.start_subentry_reconfigure_flow(hass, subentry_id)
assert ( assert result["reason"] == (
result["reason"] "Found entry entry_title,mock_entry_id: subentry_type=test/"
== "Found entry entry_title: mock_entry_id/Found subentry Test: mock_subentry_id" "Found subentry Test: mock_subentry_id"
) )
# The subentry_id does not exist # The subentry_id does not exist
@ -8097,9 +8090,9 @@ async def test_subentry_get_entry(
"subentry_id": "01JRemoved", "subentry_id": "01JRemoved",
}, },
) )
assert ( assert result["reason"] == (
result["reason"] "Found entry entry_title,mock_entry_id: subentry_type=test/"
== "Found entry entry_title: mock_entry_id/Subentry not found: 01JRemoved" "Subentry not found: 01JRemoved"
) )
# A user flow finds the config entry but not the subentry # A user flow finds the config entry but not the subentry
@ -8107,9 +8100,9 @@ async def test_subentry_get_entry(
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"] "Found entry entry_title,mock_entry_id: subentry_type=test/"
== "Found entry entry_title: mock_entry_id/Source is user, expected reconfigure: -" "Source is user, expected reconfigure: -"
) )