Ensure all default MQTT subentry option values are saved (#144347)

* Ensure all default MQTT subentry option values are saved

* Apply correct filter
This commit is contained in:
Jan Bouwhuis 2025-05-06 19:30:48 +02:00 committed by Franck Nijhof
parent ccffe19611
commit de63dddc96
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952
2 changed files with 13 additions and 3 deletions

View File

@ -1385,8 +1385,11 @@ def subentry_schema_default_data_from_fields(
return {
key: field.default
for key, field in data_schema_fields.items()
if field.is_schema_default
or (field.default is not vol.UNDEFINED and key not in component_data)
if _check_conditions(field, component_data)
and (
field.is_schema_default
or (field.default is not vol.UNDEFINED and key not in component_data)
)
}
@ -2212,7 +2215,10 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
for component_data in self._subentry_data["components"].values():
platform = component_data[CONF_PLATFORM]
subentry_default_data = subentry_schema_default_data_from_fields(
PLATFORM_ENTITY_FIELDS[platform] | COMMON_ENTITY_FIELDS, component_data
COMMON_ENTITY_FIELDS
| PLATFORM_ENTITY_FIELDS[platform]
| PLATFORM_MQTT_FIELDS[platform],
component_data,
)
component_data.update(subentry_default_data)

View File

@ -153,6 +153,10 @@ MOCK_SUBENTRY_LIGHT_BASIC_KELVIN_COMPONENT = {
"state_topic": "test-topic",
"color_temp_kelvin": True,
"state_value_template": "{{ value_json.value }}",
"brightness_scale": 255,
"max_kelvin": 6535,
"min_kelvin": 2000,
"white_scale": 255,
"entity_picture": "https://example.com/8131babc5e8d4f44b82e0761d39091a2",
},
}