mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 09:31: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(
|
async def start_subentry_reconfigure_flow(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
subentry_flow_type: str,
|
|
||||||
subentry_id: str,
|
subentry_id: str,
|
||||||
*,
|
*,
|
||||||
show_advanced_options: bool = False,
|
show_advanced_options: bool = False,
|
||||||
@ -1194,6 +1193,8 @@ class MockConfigEntry(config_entries.ConfigEntry):
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Config entry must be added to hass to start reconfiguration flow"
|
"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(
|
return await hass.config_entries.subentries.async_init(
|
||||||
(self.entry_id, subentry_flow_type),
|
(self.entry_id, subentry_flow_type),
|
||||||
context={
|
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)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "entity", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reconfigure_sensor"
|
assert result["step_id"] == "reconfigure_sensor"
|
||||||
|
|
||||||
|
@ -3309,9 +3309,7 @@ async def test_subentry_reconfigure_remove_entity(
|
|||||||
subentry_id: str
|
subentry_id: str
|
||||||
subentry: ConfigSubentry
|
subentry: ConfigSubentry
|
||||||
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
|
|
||||||
@ -3433,9 +3431,7 @@ async def test_subentry_reconfigure_edit_entity_multi_entitites(
|
|||||||
subentry_id: str
|
subentry_id: str
|
||||||
subentry: ConfigSubentry
|
subentry: ConfigSubentry
|
||||||
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
@ -3651,9 +3647,7 @@ async def test_subentry_reconfigure_edit_entity_single_entity(
|
|||||||
subentry_id: str
|
subentry_id: str
|
||||||
subentry: ConfigSubentry
|
subentry: ConfigSubentry
|
||||||
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
|
|
||||||
@ -3795,9 +3789,7 @@ async def test_subentry_reconfigure_edit_entity_reset_fields(
|
|||||||
subentry_id: str
|
subentry_id: str
|
||||||
subentry: ConfigSubentry
|
subentry: ConfigSubentry
|
||||||
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
|
|
||||||
@ -3924,9 +3916,7 @@ async def test_subentry_reconfigure_add_entity(
|
|||||||
subentry_id: str
|
subentry_id: str
|
||||||
subentry: ConfigSubentry
|
subentry: ConfigSubentry
|
||||||
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
|
|
||||||
@ -4023,9 +4013,7 @@ async def test_subentry_reconfigure_update_device_properties(
|
|||||||
subentry_id: str
|
subentry_id: str
|
||||||
subentry: ConfigSubentry
|
subentry: ConfigSubentry
|
||||||
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
subentry_id, subentry = next(iter(config_entry.subentries.items()))
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
|
|
||||||
@ -4124,9 +4112,7 @@ async def test_subentry_reconfigure_availablity(
|
|||||||
}
|
}
|
||||||
assert subentry.data.get("availability") == expected_availability
|
assert subentry.data.get("availability") == expected_availability
|
||||||
|
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_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 subentry.data.get("availability") == expected_availability
|
||||||
|
|
||||||
# Assert we can reset the availability config
|
# Assert we can reset the availability config
|
||||||
result = await config_entry.start_subentry_reconfigure_flow(
|
result = await config_entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "device", subentry_id
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.MENU
|
assert result["type"] is FlowResultType.MENU
|
||||||
assert result["step_id"] == "summary_menu"
|
assert result["step_id"] == "summary_menu"
|
||||||
result = await hass.config_entries.subentries.async_configure(
|
result = await hass.config_entries.subentries.async_configure(
|
||||||
|
@ -6497,9 +6497,7 @@ async def test_update_subentry_and_abort(
|
|||||||
err: Exception
|
err: Exception
|
||||||
with mock_config_flow("comp", TestFlow):
|
with mock_config_flow("comp", TestFlow):
|
||||||
try:
|
try:
|
||||||
result = await entry.start_subentry_reconfigure_flow(
|
result = await entry.start_subentry_reconfigure_flow(hass, subentry_id)
|
||||||
hass, "test", subentry_id
|
|
||||||
)
|
|
||||||
except Exception as ex: # noqa: BLE001
|
except Exception as ex: # noqa: BLE001
|
||||||
err = ex
|
err = ex
|
||||||
|
|
||||||
@ -6556,7 +6554,7 @@ async def test_reconfigure_subentry_create_subentry(hass: HomeAssistant) -> None
|
|||||||
mock_config_flow("comp", TestFlow),
|
mock_config_flow("comp", TestFlow),
|
||||||
pytest.raises(ValueError, match="Source is reconfigure, expected user"),
|
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()
|
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
|
# 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, subentry_id)
|
||||||
assert (
|
assert (
|
||||||
result["reason"]
|
result["reason"]
|
||||||
== "Found entry entry_title: mock_entry_id/Found subentry Test: mock_subentry_id"
|
== "Found entry entry_title: mock_entry_id/Found subentry Test: mock_subentry_id"
|
||||||
|
Reference in New Issue
Block a user