Ensure ConfirmRepairFlow can make use of translation placeholders (#76336)

* Ensure ConfirmRepairFlow can make use of translation placeholders

* Automatically determine the issue

* Fix tests

* Update homeassistant/components/repairs/issue_handler.py

Co-authored-by: Franck Nijhof <frenck@frenck.nl>

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Aaron Bach 2022-08-08 16:46:48 -06:00 committed by GitHub
parent 01de1c6304
commit 759503f863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -27,7 +27,6 @@ class ConfirmRepairFlow(RepairsFlow):
self, user_input: dict[str, str] | None = None
) -> data_entry_flow.FlowResult:
"""Handle the first step of a fix flow."""
return await (self.async_step_confirm())
async def async_step_confirm(
@ -37,7 +36,16 @@ class ConfirmRepairFlow(RepairsFlow):
if user_input is not None:
return self.async_create_entry(title="", data={})
return self.async_show_form(step_id="confirm", data_schema=vol.Schema({}))
issue_registry = async_get_issue_registry(self.hass)
description_placeholders = None
if issue := issue_registry.async_get_issue(self.handler, self.issue_id):
description_placeholders = issue.translation_placeholders
return self.async_show_form(
step_id="confirm",
data_schema=vol.Schema({}),
description_placeholders=description_placeholders,
)
class RepairsFlowManager(data_entry_flow.FlowManager):

View File

@ -253,14 +253,19 @@ async def test_fix_non_existing_issue(
@pytest.mark.parametrize(
"domain, step",
"domain, step, description_placeholders",
(
("fake_integration", "custom_step"),
("fake_integration_default_handler", "confirm"),
("fake_integration", "custom_step", None),
("fake_integration_default_handler", "confirm", {"abc": "123"}),
),
)
async def test_fix_issue(
hass: HomeAssistant, hass_client, hass_ws_client, domain, step
hass: HomeAssistant,
hass_client,
hass_ws_client,
domain,
step,
description_placeholders,
) -> None:
"""Test we can fix an issue."""
assert await async_setup_component(hass, "http", {})
@ -288,7 +293,7 @@ async def test_fix_issue(
flow_id = data["flow_id"]
assert data == {
"data_schema": [],
"description_placeholders": None,
"description_placeholders": description_placeholders,
"errors": None,
"flow_id": ANY,
"handler": domain,