mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Fix schema translation checks for nested config-flow sections (#133392)
This commit is contained in:
parent
ce0117b2b8
commit
991864b38c
@ -19,6 +19,7 @@ from aiohasupervisor.models import (
|
|||||||
StoreInfo,
|
StoreInfo,
|
||||||
)
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import repairs
|
from homeassistant.components import repairs
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
@ -34,6 +35,7 @@ from homeassistant.data_entry_flow import (
|
|||||||
FlowHandler,
|
FlowHandler,
|
||||||
FlowManager,
|
FlowManager,
|
||||||
FlowResultType,
|
FlowResultType,
|
||||||
|
section,
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
@ -644,6 +646,61 @@ def _get_integration_quality_scale_rule(integration: str, rule: str) -> str:
|
|||||||
return status if isinstance(status, str) else status["status"]
|
return status if isinstance(status, str) else status["status"]
|
||||||
|
|
||||||
|
|
||||||
|
async def _check_step_or_section_translations(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
translation_errors: dict[str, str],
|
||||||
|
category: str,
|
||||||
|
integration: str,
|
||||||
|
translation_prefix: str,
|
||||||
|
description_placeholders: dict[str, str],
|
||||||
|
data_schema: vol.Schema | None,
|
||||||
|
) -> None:
|
||||||
|
# neither title nor description are required
|
||||||
|
# - title defaults to integration name
|
||||||
|
# - description is optional
|
||||||
|
for header in ("title", "description"):
|
||||||
|
await _validate_translation(
|
||||||
|
hass,
|
||||||
|
translation_errors,
|
||||||
|
category,
|
||||||
|
integration,
|
||||||
|
f"{translation_prefix}.{header}",
|
||||||
|
description_placeholders,
|
||||||
|
translation_required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not data_schema:
|
||||||
|
return
|
||||||
|
|
||||||
|
for data_key, data_value in data_schema.schema.items():
|
||||||
|
if isinstance(data_value, section):
|
||||||
|
# check the nested section
|
||||||
|
await _check_step_or_section_translations(
|
||||||
|
hass,
|
||||||
|
translation_errors,
|
||||||
|
category,
|
||||||
|
integration,
|
||||||
|
f"{translation_prefix}.sections.{data_key}",
|
||||||
|
description_placeholders,
|
||||||
|
data_value.schema,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
iqs_config_flow = _get_integration_quality_scale_rule(
|
||||||
|
integration, "config-flow"
|
||||||
|
)
|
||||||
|
# data and data_description are compulsory
|
||||||
|
for header in ("data", "data_description"):
|
||||||
|
await _validate_translation(
|
||||||
|
hass,
|
||||||
|
translation_errors,
|
||||||
|
category,
|
||||||
|
integration,
|
||||||
|
f"{translation_prefix}.{header}.{data_key}",
|
||||||
|
description_placeholders,
|
||||||
|
translation_required=(iqs_config_flow == "done"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _check_config_flow_result_translations(
|
async def _check_config_flow_result_translations(
|
||||||
manager: FlowManager,
|
manager: FlowManager,
|
||||||
flow: FlowHandler,
|
flow: FlowHandler,
|
||||||
@ -675,34 +732,15 @@ async def _check_config_flow_result_translations(
|
|||||||
setattr(flow, "__flow_seen_before", hasattr(flow, "__flow_seen_before"))
|
setattr(flow, "__flow_seen_before", hasattr(flow, "__flow_seen_before"))
|
||||||
|
|
||||||
if result["type"] is FlowResultType.FORM:
|
if result["type"] is FlowResultType.FORM:
|
||||||
iqs_config_flow = _get_integration_quality_scale_rule(
|
|
||||||
integration, "config-flow"
|
|
||||||
)
|
|
||||||
if step_id := result.get("step_id"):
|
if step_id := result.get("step_id"):
|
||||||
# neither title nor description are required
|
await _check_step_or_section_translations(
|
||||||
# - title defaults to integration name
|
|
||||||
# - description is optional
|
|
||||||
for header in ("title", "description"):
|
|
||||||
await _validate_translation(
|
|
||||||
flow.hass,
|
flow.hass,
|
||||||
translation_errors,
|
translation_errors,
|
||||||
category,
|
category,
|
||||||
integration,
|
integration,
|
||||||
f"{key_prefix}step.{step_id}.{header}",
|
f"{key_prefix}step.{step_id}",
|
||||||
result["description_placeholders"],
|
|
||||||
translation_required=False,
|
|
||||||
)
|
|
||||||
if iqs_config_flow == "done" and (data_schema := result["data_schema"]):
|
|
||||||
# data and data_description are compulsory
|
|
||||||
for data_key in data_schema.schema:
|
|
||||||
for header in ("data", "data_description"):
|
|
||||||
await _validate_translation(
|
|
||||||
flow.hass,
|
|
||||||
translation_errors,
|
|
||||||
category,
|
|
||||||
integration,
|
|
||||||
f"{key_prefix}step.{step_id}.{header}.{data_key}",
|
|
||||||
result["description_placeholders"],
|
result["description_placeholders"],
|
||||||
|
result["data_schema"],
|
||||||
)
|
)
|
||||||
|
|
||||||
if errors := result.get("errors"):
|
if errors := result.get("errors"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user