From 7f99cd2d2be47424f348e5ec3b110a7daa3190e7 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 23 Jun 2025 15:45:33 -0400 Subject: [PATCH] Clean up start_subentry_reconfigure_flow API for tests (#147381) --- tests/common.py | 3 +- .../kitchen_sink/test_config_flow.py | 4 +-- tests/components/mqtt/test_config_flow.py | 32 +++++-------------- tests/test_config_entries.py | 8 ++--- 4 files changed, 14 insertions(+), 33 deletions(-) diff --git a/tests/common.py b/tests/common.py index d184d2b46fb..40d6e4d79d3 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1184,7 +1184,6 @@ class MockConfigEntry(config_entries.ConfigEntry): async def start_subentry_reconfigure_flow( self, hass: HomeAssistant, - subentry_flow_type: str, subentry_id: str, *, show_advanced_options: bool = False, @@ -1194,6 +1193,8 @@ class MockConfigEntry(config_entries.ConfigEntry): raise ValueError( "Config entry must be added to hass to start reconfiguration flow" ) + # Derive subentry_flow_type from the subentry_id + subentry_flow_type = self.subentries[subentry_id].subentry_type return await hass.config_entries.subentries.async_init( (self.entry_id, subentry_flow_type), context={ diff --git a/tests/components/kitchen_sink/test_config_flow.py b/tests/components/kitchen_sink/test_config_flow.py index 88bacc2cb0b..bc85edc592d 100644 --- a/tests/components/kitchen_sink/test_config_flow.py +++ b/tests/components/kitchen_sink/test_config_flow.py @@ -171,9 +171,7 @@ async def test_subentry_reconfigure_flow(hass: HomeAssistant) -> None: assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - result = await config_entry.start_subentry_reconfigure_flow( - hass, "entity", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "reconfigure_sensor" diff --git a/tests/components/mqtt/test_config_flow.py b/tests/components/mqtt/test_config_flow.py index e30aa5d50d6..a139f729cd9 100644 --- a/tests/components/mqtt/test_config_flow.py +++ b/tests/components/mqtt/test_config_flow.py @@ -3309,9 +3309,7 @@ async def test_subentry_reconfigure_remove_entity( subentry_id: str subentry: ConfigSubentry subentry_id, subentry = next(iter(config_entry.subentries.items())) - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -3433,9 +3431,7 @@ async def test_subentry_reconfigure_edit_entity_multi_entitites( subentry_id: str subentry: ConfigSubentry subentry_id, subentry = next(iter(config_entry.subentries.items())) - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -3651,9 +3647,7 @@ async def test_subentry_reconfigure_edit_entity_single_entity( subentry_id: str subentry: ConfigSubentry subentry_id, subentry = next(iter(config_entry.subentries.items())) - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -3795,9 +3789,7 @@ async def test_subentry_reconfigure_edit_entity_reset_fields( subentry_id: str subentry: ConfigSubentry subentry_id, subentry = next(iter(config_entry.subentries.items())) - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -3924,9 +3916,7 @@ async def test_subentry_reconfigure_add_entity( subentry_id: str subentry: ConfigSubentry subentry_id, subentry = next(iter(config_entry.subentries.items())) - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -4023,9 +4013,7 @@ async def test_subentry_reconfigure_update_device_properties( subentry_id: str subentry: ConfigSubentry subentry_id, subentry = next(iter(config_entry.subentries.items())) - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -4124,9 +4112,7 @@ async def test_subentry_reconfigure_availablity( } assert subentry.data.get("availability") == expected_availability - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" @@ -4174,9 +4160,7 @@ async def test_subentry_reconfigure_availablity( assert subentry.data.get("availability") == expected_availability # Assert we can reset the availability config - result = await config_entry.start_subentry_reconfigure_flow( - hass, "device", subentry_id - ) + result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id) assert result["type"] is FlowResultType.MENU assert result["step_id"] == "summary_menu" result = await hass.config_entries.subentries.async_configure( diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 55b8434160e..45bb956b7a1 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -6497,9 +6497,7 @@ async def test_update_subentry_and_abort( err: Exception with mock_config_flow("comp", TestFlow): try: - result = await entry.start_subentry_reconfigure_flow( - hass, "test", subentry_id - ) + result = await entry.start_subentry_reconfigure_flow(hass, subentry_id) except Exception as ex: # noqa: BLE001 err = ex @@ -6556,7 +6554,7 @@ async def test_reconfigure_subentry_create_subentry(hass: HomeAssistant) -> None mock_config_flow("comp", TestFlow), pytest.raises(ValueError, match="Source is reconfigure, expected user"), ): - await entry.start_subentry_reconfigure_flow(hass, "test", subentry_id) + await entry.start_subentry_reconfigure_flow(hass, subentry_id) await hass.async_block_till_done() @@ -8079,7 +8077,7 @@ async def test_subentry_get_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) + result = await entry.start_subentry_reconfigure_flow(hass, subentry_id) assert ( result["reason"] == "Found entry entry_title: mock_entry_id/Found subentry Test: mock_subentry_id"