mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Clean up start_subentry_reconfigure_flow API for tests (#147381)
This commit is contained in:
@ -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={
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user