mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix hide empty sections in mqtt subentry flows (#148692)
This commit is contained in:
parent
d4374dbcc7
commit
f7672985ed
@ -2114,6 +2114,9 @@ def data_schema_from_fields(
|
|||||||
if schema_section is None:
|
if schema_section is None:
|
||||||
data_schema.update(data_schema_element)
|
data_schema.update(data_schema_element)
|
||||||
continue
|
continue
|
||||||
|
if not data_schema_element:
|
||||||
|
# Do not show empty sections
|
||||||
|
continue
|
||||||
collapsed = (
|
collapsed = (
|
||||||
not any(
|
not any(
|
||||||
(default := data_schema_fields[str(option)].default) is vol.UNDEFINED
|
(default := data_schema_fields[str(option)].default) is vol.UNDEFINED
|
||||||
|
@ -3220,7 +3220,7 @@ async def test_subentry_configflow(
|
|||||||
"url": learn_more_url(component["platform"]),
|
"url": learn_more_url(component["platform"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Process entity details setep
|
# Process entity details step
|
||||||
assert result["step_id"] == "entity_platform_config"
|
assert result["step_id"] == "entity_platform_config"
|
||||||
|
|
||||||
# First test validators if set of test
|
# First test validators if set of test
|
||||||
@ -4212,3 +4212,52 @@ async def test_subentry_reconfigure_availablity(
|
|||||||
"payload_available": "1",
|
"payload_available": "1",
|
||||||
"payload_not_available": "0",
|
"payload_not_available": "0",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_subentry_configflow_section_feature(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
|
) -> None:
|
||||||
|
"""Test the subentry ConfigFlow sections are hidden when they have no configurable options."""
|
||||||
|
await mqtt_mock_entry()
|
||||||
|
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||||
|
|
||||||
|
result = await hass.config_entries.subentries.async_init(
|
||||||
|
(config_entry.entry_id, "device"),
|
||||||
|
context={"source": config_entries.SOURCE_USER},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "device"
|
||||||
|
result = await hass.config_entries.subentries.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={"name": "Bla", "mqtt_settings": {"qos": 1}},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
|
||||||
|
result = await hass.config_entries.subentries.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={"platform": "fan"},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["description_placeholders"] == {
|
||||||
|
"mqtt_device": "Bla",
|
||||||
|
"platform": "fan",
|
||||||
|
"entity": "Bla",
|
||||||
|
"url": learn_more_url("fan"),
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process entity details step
|
||||||
|
assert result["step_id"] == "entity_platform_config"
|
||||||
|
|
||||||
|
result = await hass.config_entries.subentries.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={"fan_feature_speed": True},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["errors"] == {}
|
||||||
|
assert result["step_id"] == "mqtt_platform_config"
|
||||||
|
|
||||||
|
# Check mqtt platform config flow sections from data schema
|
||||||
|
data_schema = result["data_schema"].schema
|
||||||
|
assert "fan_speed_settings" in data_schema
|
||||||
|
assert "fan_preset_mode_settings" not in data_schema
|
||||||
|
Loading…
x
Reference in New Issue
Block a user