Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
epenet
bf207f6135 Ignore fake_integration in repairs 2024-11-14 15:28:07 +00:00
epenet
5192aa52bf Add translation checks for repair flows 2024-11-14 15:28:07 +00:00
2 changed files with 20 additions and 3 deletions

View file

@ -18,6 +18,7 @@ from aiohasupervisor.models import (
) )
import pytest import pytest
from homeassistant.components import repairs
from homeassistant.config_entries import ( from homeassistant.config_entries import (
DISCOVERY_SOURCES, DISCOVERY_SOURCES,
ConfigEntriesFlowManager, ConfigEntriesFlowManager,
@ -32,6 +33,7 @@ from homeassistant.data_entry_flow import (
FlowManager, FlowManager,
FlowResultType, FlowResultType,
) )
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.translation import async_get_translations from homeassistant.helpers.translation import async_get_translations
if TYPE_CHECKING: if TYPE_CHECKING:
@ -615,12 +617,23 @@ async def _check_config_flow_result_translations(
result: FlowResult[FlowContext, str], result: FlowResult[FlowContext, str],
ignore_translations: dict[str, str], ignore_translations: dict[str, str],
) -> None: ) -> None:
if result["type"] is FlowResultType.CREATE_ENTRY:
# No need to check translations for a completed flow
return
key_prefix = ""
if isinstance(manager, ConfigEntriesFlowManager): if isinstance(manager, ConfigEntriesFlowManager):
category = "config" category = "config"
integration = flow.handler integration = flow.handler
elif isinstance(manager, OptionsFlowManager): elif isinstance(manager, OptionsFlowManager):
category = "options" category = "options"
integration = flow.hass.config_entries.async_get_entry(flow.handler).domain integration = flow.hass.config_entries.async_get_entry(flow.handler).domain
elif isinstance(manager, repairs.RepairsFlowManager):
category = "issues"
integration = flow.handler
issue_id = flow.issue_id
issue = ir.async_get(flow.hass).async_get_issue(integration, issue_id)
key_prefix = f"{issue.translation_key}.fix_flow."
else: else:
return return
@ -639,7 +652,7 @@ async def _check_config_flow_result_translations(
ignore_translations, ignore_translations,
category, category,
integration, integration,
f"step.{step_id}.{header}", f"{key_prefix}step.{step_id}.{header}",
result["description_placeholders"], result["description_placeholders"],
translation_required=False, translation_required=False,
) )
@ -650,7 +663,7 @@ async def _check_config_flow_result_translations(
ignore_translations, ignore_translations,
category, category,
integration, integration,
f"error.{error}", f"{key_prefix}error.{error}",
result["description_placeholders"], result["description_placeholders"],
) )
return return
@ -665,7 +678,7 @@ async def _check_config_flow_result_translations(
ignore_translations, ignore_translations,
category, category,
integration, integration,
f"abort.{result["reason"]}", f"{key_prefix}abort.{result["reason"]}",
result["description_placeholders"], result["description_placeholders"],
) )

View file

@ -533,6 +533,10 @@ async def test_list_issues(
} }
@pytest.mark.parametrize(
"ignore_translations",
["component.fake_integration.issues.abc_123.fix_flow.abort.not_given"],
)
async def test_fix_issue_aborted( async def test_fix_issue_aborted(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,