Fix field validation for mqtt subentry options in sections (#144355)

This commit is contained in:
Jan Bouwhuis 2025-05-07 09:24:51 +02:00 committed by GitHub
parent 65278100a0
commit 358d904c2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -526,8 +526,7 @@ def validate_light_platform_config(user_data: dict[str, Any]) -> dict[str, str]:
if user_data.get(CONF_MIN_KELVIN, DEFAULT_MIN_KELVIN) >= user_data.get(
CONF_MAX_KELVIN, DEFAULT_MAX_KELVIN
):
errors[CONF_MAX_KELVIN] = "max_below_min_kelvin"
errors[CONF_MIN_KELVIN] = "max_below_min_kelvin"
errors["advanced_settings"] = "max_below_min_kelvin"
return errors
@ -1381,7 +1380,10 @@ def validate_user_input(
try:
validator(value)
except (ValueError, vol.Error, vol.Invalid):
errors[field] = data_schema_fields[field].error or "invalid_input"
data_schema_field = data_schema_fields[field]
errors[data_schema_field.section or field] = (
data_schema_field.error or "invalid_input"
)
if config_validator is not None:
if TYPE_CHECKING:

View File

@ -2858,14 +2858,22 @@ async def test_migrate_of_incompatible_config_entry(
},
{"state_topic": "invalid_subscribe_topic"},
),
(
{
"command_topic": "test-topic",
"light_brightness_settings": {
"brightness_command_topic": "test-topic#invalid"
},
},
{"light_brightness_settings": "invalid_publish_topic"},
),
(
{
"command_topic": "test-topic",
"advanced_settings": {"max_kelvin": 2000, "min_kelvin": 2000},
},
{
"max_kelvin": "max_below_min_kelvin",
"min_kelvin": "max_below_min_kelvin",
"advanced_settings": "max_below_min_kelvin",
},
),
),